This is an automated email from the ASF dual-hosted git repository. cmcfarlen pushed a commit to branch 10.0.x in repository https://gitbox.apache.org/repos/asf/trafficserver.git
commit da873dcb9963218faefc166dc4fc97ded8b88463 Author: Leif Hedstrom <[email protected]> AuthorDate: Mon Mar 18 14:44:46 2024 -0600 Adds TSHttpTxnErrorBodyGet() corresponding to the Set (#11163) * Adds TSHttpTxnErrorBodyGet() corresponding to the Set * Adds documentation (cherry picked from commit 98e60108c8a527ab630344639b417f8c2fbdb411) --- .../api/functions/TSHttpTxnErrorBodySet.en.rst | 21 +++++++++++++++++++++ include/ts/ts.h | 10 ++++++++++ src/api/InkAPI.cc | 19 +++++++++++++++++++ 3 files changed, 50 insertions(+) diff --git a/doc/developer-guide/api/functions/TSHttpTxnErrorBodySet.en.rst b/doc/developer-guide/api/functions/TSHttpTxnErrorBodySet.en.rst index 082ba18d7b..89b602dd7c 100644 --- a/doc/developer-guide/api/functions/TSHttpTxnErrorBodySet.en.rst +++ b/doc/developer-guide/api/functions/TSHttpTxnErrorBodySet.en.rst @@ -39,3 +39,24 @@ Note that both string arguments must be allocated with :c:func:`TSmalloc` or :c:func:`TSstrdup`. The :arg:`mimetype` is optional, and if not provided it defaults to :literal:`text/html`. Sending an empty string would prevent setting a content type header (but that is not advised). + + +TSHttpTxnErrorBodyGet +********************* + +Gets the error body as set above. + +Synopsis +======== + +.. code-block:: cpp + + #include <ts/ts.h> + +.. function:: char * TSHttpTxnErrorBodyGet(TSHttpTxn txnp, size_t *buflength, char **mimetype) + +Description +=========== + +This is the getter version for the above setter. The :arg:`mimetype` and the :arg:`buflength` +arguments can be :const:`nullptr` if the caller is not interested in the mimetype or the length. diff --git a/include/ts/ts.h b/include/ts/ts.h index b244610a8b..956963faae 100644 --- a/include/ts/ts.h +++ b/include/ts/ts.h @@ -1599,6 +1599,16 @@ TSReturnCode TSHttpTxnServerPacketDscpSet(TSHttpTxn txnp, int dscp); */ void TSHttpTxnErrorBodySet(TSHttpTxn txnp, char *buf, size_t buflength, char *mimetype); +/** + Retrives the error body, if any, from a transaction. This would be a body as set + via the API body. + + @param txnp HTTP transaction whose parent proxy to get. + @param buflength Optional outpu pointer to the length of the body message. + @param mimetype Optional output pointer to the MIME type of the response. +*/ +char *TSHttpTxnErrorBodyGet(TSHttpTxn txnp, size_t *buflength, char **mimetype); + /** Retrieves the parent proxy hostname and port, if parent proxying is enabled. If parent proxying is not enabled, diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc index dffa5d236a..17c10b3bba 100644 --- a/src/api/InkAPI.cc +++ b/src/api/InkAPI.cc @@ -4760,6 +4760,25 @@ TSHttpTxnErrorBodySet(TSHttpTxn txnp, char *buf, size_t buflength, char *mimetyp s->internal_msg_buffer_type = mimetype; } +char * +TSHttpTxnErrorBodyGet(TSHttpTxn txnp, size_t *buflength, char **mimetype) +{ + sdk_assert(sdk_sanity_check_txn(txnp) == TS_SUCCESS); + + HttpSM *sm = (HttpSM *)txnp; + HttpTransact::State *s = &(sm->t_state); + + if (buflength) { + *buflength = s->internal_msg_buffer_size; + } + + if (mimetype) { + *mimetype = s->internal_msg_buffer_type; + } + + return s->internal_msg_buffer; +} + void TSHttpTxnServerRequestBodySet(TSHttpTxn txnp, char *buf, int64_t buflength) {
