Skip to content

Commit f980afa

Browse files
committed
Fix bug introduced in #349
See: #349 Fix bug for non-chucked responses without a known content-length (see LargeResponse example)
1 parent 84ad2b6 commit f980afa

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

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)