Skip to content

Commit 08763f3

Browse files
Merge pull request #363 from ESP32Async/fix-349
URGENT - Fix bug introduced in #349
2 parents 84ad2b6 + f980afa commit 08763f3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/WebResponses.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,16 @@ size_t AsyncAbstractResponse::write_send_buffs(AsyncWebServerRequest *request, s
470470
}
471471
}
472472
} else {
473-
size_t const readLen =
474-
_fillBufferAndProcessTemplates(_send_buffer->data(), std::min(std::min(_send_buffer->size(), tcp_win), _contentLength - _sentLength));
473+
// Non-chunked data. We can either have a response:
474+
// - with a known content-length (example: Json response), in that case we pass the remaining length if lower than tcp_win
475+
// - or with unknown content-length (see LargeResponse example, like ESP32Cam with streaming), in that case we just fill as much as tcp_win allows
476+
size_t maxLen = std::min(_send_buffer->size(), tcp_win);
477+
if (_contentLength) {
478+
maxLen = _contentLength > _sentLength ? std::min(maxLen, _contentLength - _sentLength) : 0;
479+
}
480+
481+
size_t const readLen = _fillBufferAndProcessTemplates(_send_buffer->data(), maxLen);
482+
475483
if (readLen == 0) {
476484
// no more data to send
477485
_state = RESPONSE_END;

0 commit comments

Comments
 (0)