fix(webserver): Cap size of last chunk in raw read in WebServer

Before, the raw read would time out if the content length was not a multiple
of HTTP_RAW_BUFLEN, as it tried to read HTTP_RAW_BUFLEN bytes even if the
last chunk should actually contain less.
This commit is contained in:
Marcos Del Sol Vives 2024-12-13 02:55:30 +01:00
parent fb6e977aa8
commit 784ef0f286
No known key found for this signature in database

View file

@ -186,8 +186,12 @@ bool WebServer::_parseRequest(NetworkClient &client) {
_currentHandler->raw(*this, _currentUri, *_currentRaw);
_currentRaw->status = RAW_WRITE;
while (_currentRaw->totalSize < _clientContentLength) {
_currentRaw->currentSize = client.readBytes(_currentRaw->buf, HTTP_RAW_BUFLEN);
while (1) {
size_t read_len = std::min(_clientContentLength - _currentRaw->totalSize, (size_t) HTTP_RAW_BUFLEN);
if (read_len == 0) {
break;
}
_currentRaw->currentSize = client.readBytes(_currentRaw->buf, read_len);
_currentRaw->totalSize += _currentRaw->currentSize;
if (_currentRaw->currentSize == 0) {
_currentRaw->status = RAW_ABORTED;