Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate Content-Length header with same values #45

Merged
merged 1 commit into from
Oct 4, 2017
Merged
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
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