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.
This commit is contained in:
Adam Matthews authored and GitHub committed 2026-10-15 09:35:15 +02:00
1 parent 770960cec8
commit 90754c5b93
1 file changed
+3 -14
@@ -1022,12 +1022,7 @@ int AsyncHttpClientLight::Job_WriteToStream(void* arg) {
int chunk = (int) strtol(h.c_str(), nullptr, 16); int chunk = (int) strtol(h.c_str(), nullptr, 16);
if (chunk <= 0) { if (chunk <= 0) {
String tmp; // after the last chunk: trailer lines, if any, up to an empty line
if (!readLine(tmp)) {
if (a->self->_transport) a->self->_transport->stop();
a->self->_bodyPending = false;
return HTTPC_ERROR_READ_TIMEOUT;
}
while (true) { while (true) {
String t; String t;
if (!readLine(t)) { if (!readLine(t)) {
@@ -1143,12 +1138,7 @@ int AsyncHttpClientLight::Job_GetString(void* arg) {
int chunk = (int) strtol(h.c_str(), nullptr, 16); int chunk = (int) strtol(h.c_str(), nullptr, 16);
if (chunk <= 0) { if (chunk <= 0) {
String tmp; // after the last chunk: trailer lines, if any, up to an empty line
if (!readLine(tmp)) {
if (a->self->_transport) a->self->_transport->stop();
a->self->_bodyPending = false;
return HTTPC_ERROR_READ_TIMEOUT;
}
while (true) { while (true) {
String t; String t;
if (!readLine(t)) { if (!readLine(t)) {
@@ -1296,8 +1286,7 @@ int AsyncHttpClientLight::readBodyToStreamString(StreamString& s, int size_limit
h.trim(); h.trim();
int chunk = (int) strtol(h.c_str(), nullptr, 16); int chunk = (int) strtol(h.c_str(), nullptr, 16);
if (chunk <= 0) { if (chunk <= 0) {
String tmp; // after the last chunk: trailer lines, if any, up to an empty line
if (!readLine(tmp)) return bail(HTTPC_ERROR_READ_TIMEOUT);
while (true) { String t; if (!readLine(t)) return bail(HTTPC_ERROR_READ_TIMEOUT); if (t.length() == 0) break; } while (true) { String t; if (!readLine(t)) return bail(HTTPC_ERROR_READ_TIMEOUT); if (t.length() == 0) break; }
break; // end break; // end
} }