Skip to content

Commit 1f7aec1

Browse files
committed
merging pull request fhessel#123
1 parent 4afc790 commit 1f7aec1

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/HTTPConnection.cpp

+15-14
Original file line numberDiff line numberDiff line change
@@ -290,23 +290,24 @@ void HTTPConnection::readLine(int lengthLimit) {
290290
while(_bufferProcessed < _bufferUnusedIdx) {
291291
char newChar = _receiveBuffer[_bufferProcessed];
292292

293-
if ( newChar == '\r') {
294-
// Look ahead for \n (if not possible, wait for next round
295-
if (_bufferProcessed+1 < _bufferUnusedIdx) {
296-
if (_receiveBuffer[_bufferProcessed+1] == '\n') {
297-
_bufferProcessed += 2;
298-
_parserLine.parsingFinished = true;
299-
return;
300-
} else {
301-
// Line has not been terminated by \r\n
302-
HTTPS_LOGW("Line without \\r\\n (got only \\r). FID=%d", _socket);
303-
raiseError(400, "Bad Request");
304-
return;
305-
}
293+
_bufferProcessed++;
294+
if ( partialTerminationParsed ){
295+
partialTerminationParsed = false;
296+
if (newChar == '\n') {
297+
_parserLine.parsingFinished = true;
298+
} else {
299+
// Line has not been terminated by \r\n
300+
HTTPS_LOGW("Line without \\r\\n (got only \\r). FID=%d", _socket);
301+
raiseError(400, "Bad Request");
306302
}
303+
return;
304+
}
305+
306+
if ( newChar == '\r'){
307+
partialTerminationParsed = true;
307308
} else {
308309
_parserLine.text += newChar;
309-
_bufferProcessed += 1;
310+
310311
}
311312

312313
// Check that the max request string size is not exceeded

src/HTTPConnection.hpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ class HTTPConnection : private ConnectionContext {
131131
int _bufferProcessed;
132132
// The index on the receive_buffer that is the first one which is empty at the end.
133133
int _bufferUnusedIdx;
134-
134+
bool partialTerminationParsed = false;
135+
135136
// Socket address, length etc for the connection
136137
struct sockaddr _sockAddr;
137138
socklen_t _addrLen;

0 commit comments

Comments
 (0)