From 90754c5b93d3cda75fda3cb158e2a9a16678732a Mon Sep 17 00:00:00 2001 From: Adam Matthews <52178922+adamsthws@users.noreply.github.com> Date: Thu, 15 Oct 2026 08:35:15 +0100 Subject: [PATCH] AsyncHttpClientLight: finish a chunked body at the empty line after the last chunk (#25142) After the zero-size chunk the readers read one line unconditionally, then waited for another empty line. The first read already consumed the empty line that ends the body, so every chunked body waited for a line that never came and failed with HTTPC_ERROR_READ_TIMEOUT after _tcpTimeout. Read trailer lines up to the first empty one instead. --- .../src/AsyncHttpClientLight.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/lib/libesp32/AsyncHttpClientLight/src/AsyncHttpClientLight.cpp b/lib/libesp32/AsyncHttpClientLight/src/AsyncHttpClientLight.cpp index 91079c194..7cfdb8a2d 100644 --- a/lib/libesp32/AsyncHttpClientLight/src/AsyncHttpClientLight.cpp +++ b/lib/libesp32/AsyncHttpClientLight/src/AsyncHttpClientLight.cpp @@ -1022,12 +1022,7 @@ int AsyncHttpClientLight::Job_WriteToStream(void* arg) { int chunk = (int) strtol(h.c_str(), nullptr, 16); if (chunk <= 0) { - String tmp; - if (!readLine(tmp)) { - if (a->self->_transport) a->self->_transport->stop(); - a->self->_bodyPending = false; - return HTTPC_ERROR_READ_TIMEOUT; - } + // after the last chunk: trailer lines, if any, up to an empty line while (true) { String t; if (!readLine(t)) { @@ -1143,12 +1138,7 @@ int AsyncHttpClientLight::Job_GetString(void* arg) { int chunk = (int) strtol(h.c_str(), nullptr, 16); if (chunk <= 0) { - String tmp; - if (!readLine(tmp)) { - if (a->self->_transport) a->self->_transport->stop(); - a->self->_bodyPending = false; - return HTTPC_ERROR_READ_TIMEOUT; - } + // after the last chunk: trailer lines, if any, up to an empty line while (true) { String t; if (!readLine(t)) { @@ -1296,8 +1286,7 @@ int AsyncHttpClientLight::readBodyToStreamString(StreamString& s, int size_limit h.trim(); int chunk = (int) strtol(h.c_str(), nullptr, 16); if (chunk <= 0) { - String tmp; - if (!readLine(tmp)) return bail(HTTPC_ERROR_READ_TIMEOUT); + // after the last chunk: trailer lines, if any, up to an empty line while (true) { String t; if (!readLine(t)) return bail(HTTPC_ERROR_READ_TIMEOUT); if (t.length() == 0) break; } break; // end }