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

cmcfarlen pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/trafficserver.git

commit 3e31cfe57f65e55f7dcee1d3094dc4be31d77d1e
Author: Brian Olsen <[email protected]>
AuthorDate: Tue Dec 2 16:42:49 2025 -0700

    Fix for fetchsm chunked response handling with dechunking turned off 
(#12707)
    
    * FetchSM: fix for chunked response but no dechunking
    
    * add lua support so that the fetchsm code can be tested
    
    ---------
    
    Co-authored-by: Brian Olsen <[email protected]>
    (cherry picked from commit abf073f91137749ee3c695a56adf3b1754f8c3c3)
---
 doc/admin-guide/plugins/lua.en.rst |  6 ++++--
 plugins/lua/ts_lua_fetch.cc        |  3 +++
 src/proxy/FetchSM.cc               | 13 +++++++++----
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/doc/admin-guide/plugins/lua.en.rst 
b/doc/admin-guide/plugins/lua.en.rst
index d065d3d1e3..9650a93502 100644
--- a/doc/admin-guide/plugins/lua.en.rst
+++ b/doc/admin-guide/plugins/lua.en.rst
@@ -3666,11 +3666,13 @@ We can set the optional table with several members:
 
 ``cliaddr`` holds the request client address in ip:port form. The default 
cliaddr is '127.0.0.1:33333'
 
-Issuing a post request:
+``option`` holds request options. 'c' is to not dechunk chunked content, 's' 
is to skip remap config and go direct.
+
+Issuing a direct post request:
 
 ::
 
-    res = ts.fetch('http://xx.com/foo', {method = 'POST', body = 'hello 
world'})
+    res = ts.fetch('http://xx.com/foo', {method = 'POST', body = 'hello 
world', option = 's' })
 
 :ref:`TOP <admin-plugins-ts-lua>`
 
diff --git a/plugins/lua/ts_lua_fetch.cc b/plugins/lua/ts_lua_fetch.cc
index 38b0b3802e..b14b918eab 100644
--- a/plugins/lua/ts_lua_fetch.cc
+++ b/plugins/lua/ts_lua_fetch.cc
@@ -298,6 +298,9 @@ ts_lua_fetch_one_item(lua_State *L, const char *url, size_t 
url_len, ts_lua_fetc
         case 'c':
           flags &= (~TS_FETCH_FLAGS_DECHUNK);
           break;
+        case 's':
+          flags |= (TS_FETCH_FLAGS_SKIP_REMAP);
+          break;
 
         default:
           break;
diff --git a/src/proxy/FetchSM.cc b/src/proxy/FetchSM.cc
index 6b84929774..3089bf2984 100644
--- a/src/proxy/FetchSM.cc
+++ b/src/proxy/FetchSM.cc
@@ -295,6 +295,9 @@ FetchSM::InvokePluginExt(int fetch_event)
     MUTEX_TAKE_LOCK(cont_mutex, mythread);
   }
 
+  bool const dechunk = 0 != (fetch_flags & TS_FETCH_FLAGS_DECHUNK);
+  bool       chunked = false;
+
   if (!contp) {
     goto out;
   }
@@ -330,11 +333,13 @@ FetchSM::InvokePluginExt(int fetch_event)
     goto out;
   }
 
+  chunked = check_chunked();
+
   Dbg(dbg_ctl, "[%s] chunked:%d, content_len: %" PRId64 ", received_len: %" 
PRId64 ", avail: %" PRId64 "", __FUNCTION__,
       resp_is_chunked, resp_content_length, resp_received_body_len,
-      resp_is_chunked > 0 ? chunked_handler.chunked_reader->read_avail() : 
resp_reader->read_avail());
+      chunked && dechunk ? chunked_handler.chunked_reader->read_avail() : 
resp_reader->read_avail());
 
-  if (resp_is_chunked > 0) {
+  if (chunked && dechunk) {
     if (!chunked_handler.chunked_reader->read_avail()) {
       if (read_complete_event) {
         contp->handleEvent(TS_FETCH_EVENT_EXT_BODY_DONE, this);
@@ -348,13 +353,13 @@ FetchSM::InvokePluginExt(int fetch_event)
     goto out;
   }
 
-  if (!check_chunked()) {
+  if (!chunked) {
     if (!check_body_done() && !read_complete_event) {
       contp->handleEvent(TS_FETCH_EVENT_EXT_BODY_READY, this);
     } else {
       contp->handleEvent(TS_FETCH_EVENT_EXT_BODY_DONE, this);
     }
-  } else if (fetch_flags & TS_FETCH_FLAGS_DECHUNK) {
+  } else if (dechunk) {
     do {
       if (chunked_handler.state == ChunkedHandler::CHUNK_FLOW_CONTROL) {
         chunked_handler.state = ChunkedHandler::CHUNK_READ_SIZE_START;

Reply via email to