Skip to content

Commit 784ef0f

Browse files
committed
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.
1 parent fb6e977 commit 784ef0f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: libraries/WebServer/src/Parsing.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,12 @@ bool WebServer::_parseRequest(NetworkClient &client) {
186186
_currentHandler->raw(*this, _currentUri, *_currentRaw);
187187
_currentRaw->status = RAW_WRITE;
188188

189-
while (_currentRaw->totalSize < _clientContentLength) {
190-
_currentRaw->currentSize = client.readBytes(_currentRaw->buf, HTTP_RAW_BUFLEN);
189+
while (1) {
190+
size_t read_len = std::min(_clientContentLength - _currentRaw->totalSize, (size_t) HTTP_RAW_BUFLEN);
191+
if (read_len == 0) {
192+
break;
193+
}
194+
_currentRaw->currentSize = client.readBytes(_currentRaw->buf, read_len);
191195
_currentRaw->totalSize += _currentRaw->currentSize;
192196
if (_currentRaw->currentSize == 0) {
193197
_currentRaw->status = RAW_ABORTED;

0 commit comments

Comments
 (0)