Skip to content

Commit abf073f

Browse files
traeakBrian Olsen
andauthored
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]>
1 parent 0039a4d commit abf073f

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

doc/admin-guide/plugins/lua.en.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3864,11 +3864,13 @@ We can set the optional table with several members:
38643864

38653865
``cliaddr`` holds the request client address in ip:port form. The default cliaddr is '127.0.0.1:33333'
38663866

3867-
Issuing a post request:
3867+
``option`` holds request options. 'c' is to not dechunk chunked content, 's' is to skip remap config and go direct.
3868+
3869+
Issuing a direct post request:
38683870

38693871
::
38703872

3871-
res = ts.fetch('http://xx.com/foo', {method = 'POST', body = 'hello world'})
3873+
res = ts.fetch('http://xx.com/foo', {method = 'POST', body = 'hello world', option = 's' })
38723874

38733875
:ref:`TOP <admin-plugins-ts-lua>`
38743876

plugins/lua/ts_lua_fetch.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ ts_lua_fetch_one_item(lua_State *L, const char *url, size_t url_len, ts_lua_fetc
298298
case 'c':
299299
flags &= (~TS_FETCH_FLAGS_DECHUNK);
300300
break;
301+
case 's':
302+
flags |= (TS_FETCH_FLAGS_SKIP_REMAP);
303+
break;
301304

302305
default:
303306
break;

src/proxy/FetchSM.cc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,9 @@ FetchSM::InvokePluginExt(int fetch_event)
293293
MUTEX_TAKE_LOCK(cont_mutex, mythread);
294294
}
295295

296+
bool const dechunk = 0 != (fetch_flags & TS_FETCH_FLAGS_DECHUNK);
297+
bool chunked = false;
298+
296299
if (!contp) {
297300
goto out;
298301
}
@@ -328,11 +331,13 @@ FetchSM::InvokePluginExt(int fetch_event)
328331
goto out;
329332
}
330333

334+
chunked = check_chunked();
335+
331336
Dbg(dbg_ctl, "[%s] chunked:%d, content_len: %" PRId64 ", received_len: %" PRId64 ", avail: %" PRId64 "", __FUNCTION__,
332337
resp_is_chunked, resp_content_length, resp_received_body_len,
333-
resp_is_chunked > 0 ? chunked_handler.chunked_reader->read_avail() : resp_reader->read_avail());
338+
chunked && dechunk ? chunked_handler.chunked_reader->read_avail() : resp_reader->read_avail());
334339

335-
if (resp_is_chunked > 0) {
340+
if (chunked && dechunk) {
336341
if (!chunked_handler.chunked_reader->read_avail()) {
337342
if (read_complete_event) {
338343
contp->handleEvent(TS_FETCH_EVENT_EXT_BODY_DONE, this);
@@ -346,13 +351,13 @@ FetchSM::InvokePluginExt(int fetch_event)
346351
goto out;
347352
}
348353

349-
if (!check_chunked()) {
354+
if (!chunked) {
350355
if (!check_body_done() && !read_complete_event) {
351356
contp->handleEvent(TS_FETCH_EVENT_EXT_BODY_READY, this);
352357
} else {
353358
contp->handleEvent(TS_FETCH_EVENT_EXT_BODY_DONE, this);
354359
}
355-
} else if (fetch_flags & TS_FETCH_FLAGS_DECHUNK) {
360+
} else if (dechunk) {
356361
do {
357362
if (chunked_handler.state == ChunkedHandler::ChunkedState::FLOW_CONTROL) {
358363
chunked_handler.state = ChunkedHandler::ChunkedState::READ_SIZE_START;

0 commit comments

Comments
 (0)