[
https://issues.apache.org/jira/browse/TS-4144?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15128194#comment-15128194
]
ASF GitHub Bot commented on TS-4144:
------------------------------------
Github user bgaff commented on a diff in the pull request:
https://github.com/apache/trafficserver/pull/435#discussion_r51563391
--- Diff: lib/atscppapi/src/Transaction.cc ---
@@ -186,6 +186,20 @@ Transaction::setErrorBody(const std::string &page)
TSHttpTxnErrorBodySet(state_->txn_, TSstrdup(page.c_str()),
page.length(), NULL); // Default to text/html
}
+void
+Transaction::setErrorBody(const std::string &page, const std::string
&mimetype)
+{
+ LOG_DEBUG("Transaction tshttptxn=%p setting error body page: %s",
state_->txn_, page.c_str());
+ TSHttpTxnErrorBodySet(state_->txn_, TSstrdup(page.c_str()),
page.length(), TSstrdup(mimetype.c_str()));
--- End diff --
I'm totally good w/ this addition but there is a bug that was recently
identified in `Transaction::setErrorBody()`, if someone passes a binary string
in for page it will result in weird truncation because of the use of string
functions. The code needs to change to be:
`
char *body = (char*)TSmalloc(page.length());
memcpy(body, page.data(), page.length());
TSHttpTxnErrorBodySet(state_->txn_, body, page.length(),
TSstrdup(mimetype.c_str()));
`
Can you make this change to both versions of `Transaction::setErrorBody()`?
> Add custom error response support in RemapPlugin of cppapi
> ----------------------------------------------------------
>
> Key: TS-4144
> URL: https://issues.apache.org/jira/browse/TS-4144
> Project: Traffic Server
> Issue Type: Improvement
> Components: CPP API
> Reporter: yukihisa ishimura
> Assignee: Brian Geffon
> Fix For: 6.2.0
>
>
> In my use case, I’d like to return custom response from my plugin using
> RemapPlugin of CPP API.
> It looks like there are lack of supports in below.
> 1. Transaction class has setErrorBody to set body, but it has no method to
> set http status code.
> 2. {{setErrorBody}} method in Transaction class doesn’t have option to
> mimetype
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)