Skip to content

Commit

Permalink
Merge pull request #45 from itteco/fix-duplicate-content-length
Browse files Browse the repository at this point in the history
Fix duplicate Content-Length header with same values
  • Loading branch information
Jimbly committed Oct 4, 2017
2 parents 4c27a07 + fbecb26 commit 570c10c
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions http-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,17 +279,27 @@ HTTPParser.prototype.HEADER = function () {
} else {
var headers = info.headers;
var hasContentLength = false;
var currentContentLengthValue;
for (var i = 0; i < headers.length; i += 2) {
switch (headers[i].toLowerCase()) {
case 'transfer-encoding':
this.isChunked = headers[i + 1].toLowerCase() === 'chunked';
break;
case 'content-length':
currentContentLengthValue = +headers[i + 1];
if (hasContentLength) {
throw parseErrorCode('HPE_UNEXPECTED_CONTENT_LENGTH');
// Fix duplicate Content-Length header with same values.
// Throw error only if values are different.
// Known issues:
// https://github.com/request/request/issues/2091#issuecomment-328715113
// https://github.com/nodejs/node/issues/6517#issuecomment-216263771
if (currentContentLengthValue !== this.body_bytes) {
throw parseErrorCode('HPE_UNEXPECTED_CONTENT_LENGTH');
}
} else {
hasContentLength = true;
this.body_bytes = currentContentLengthValue;
}
hasContentLength = true;
this.body_bytes = +headers[i + 1];
break;
case 'connection':
this.connection += headers[i + 1].toLowerCase();
Expand Down

0 comments on commit 570c10c

Please sign in to comment.