You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by zw...@apache.org on 2024/03/18 20:44:51 UTC

(trafficserver) branch master updated: Adds TSHttpTxnErrorBodyGet() corresponding to the Set (#11163)

This is an automated email from the ASF dual-hosted git repository.

zwoop pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new 98e60108c8 Adds TSHttpTxnErrorBodyGet() corresponding to the Set (#11163)
98e60108c8 is described below

commit 98e60108c8a527ab630344639b417f8c2fbdb411
Author: Leif Hedstrom <zw...@apache.org>
AuthorDate: Mon Mar 18 14:44:46 2024 -0600

    Adds TSHttpTxnErrorBodyGet() corresponding to the Set (#11163)
    
    * Adds TSHttpTxnErrorBodyGet() corresponding to the Set
    
    * Adds documentation
---
 .../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 6b7ebcc874..d4fbfe2f88 100644
--- a/include/ts/ts.h
+++ b/include/ts/ts.h
@@ -1602,6 +1602,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 a69938cfd6..35cb7edc94 100644
--- a/src/api/InkAPI.cc
+++ b/src/api/InkAPI.cc
@@ -4848,6 +4848,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)
 {