Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions http-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,13 @@ HTTPParser.prototype.HEADER = function () {
} else {
var headers = info.headers;
var hasContentLength = false;
var hasTransferEncoding = false;
var currentContentLengthValue;
var hasUpgradeHeader = false;
for (var i = 0; i < headers.length; i += 2) {
switch (headers[i].toLowerCase()) {
case 'transfer-encoding':
hasTransferEncoding = true;
this.isChunked = headers[i + 1].toLowerCase() === 'chunked';
break;
case 'content-length':
Expand Down Expand Up @@ -328,6 +330,12 @@ HTTPParser.prototype.HEADER = function () {
}
}

// Logic from https://github.com/nodejs/llhttp/blob/dc5dc9a018214ae767a86bb5b0c69983d272d21e/src/native/http.c#L142-L146
// If there is no content length, no transfer encoding, and there is data in the body, throw.
if (this.type === HTTPParser.REQUEST && !hasUpgradeHeader && !hasContentLength && !hasTransferEncoding && (this.end - this.offset) > 0) {
throw parseErrorCode('HPE_INVALID_METHOD');
}

// if both isChunked and hasContentLength, isChunked wins
// This is required so the body is parsed using the chunked method, and matches
// Chrome's behavior. We could, maybe, ignore them both (would get chunked
Expand Down
Loading