Skip to content

Commit 9e5daea

Browse files
kylecarbsJimbly
authored andcommitted
Fix body parsing
This was broken by: nodejs/node@b970634
1 parent 48c3de1 commit 9e5daea

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

http-parser.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ HTTPParser.prototype.reinitialize = HTTPParser;
100100
HTTPParser.prototype.close =
101101
HTTPParser.prototype.pause =
102102
HTTPParser.prototype.resume =
103+
HTTPParser.prototype.remove =
103104
HTTPParser.prototype.free = function () {};
104105
HTTPParser.prototype._compatMode0_11 = false;
105106
HTTPParser.prototype.getAsyncId = function() { return 0; };
@@ -394,7 +395,8 @@ HTTPParser.prototype.BODY_CHUNKHEAD = function () {
394395

395396
HTTPParser.prototype.BODY_CHUNK = function () {
396397
var length = Math.min(this.end - this.offset, this.body_bytes);
397-
this.userCall()(this[kOnBody](this.chunk, this.offset, length));
398+
// 0, length are for backwards compatibility. See: https://github.com/creationix/http-parser-js/pull/98
399+
this.userCall()(this[kOnBody](this.chunk.slice(this.offset, this.offset + length), 0, length));
398400
this.offset += length;
399401
this.body_bytes -= length;
400402
if (!this.body_bytes) {
@@ -429,14 +431,15 @@ HTTPParser.prototype.BODY_CHUNKTRAILERS = function () {
429431
};
430432

431433
HTTPParser.prototype.BODY_RAW = function () {
432-
var length = this.end - this.offset;
433-
this.userCall()(this[kOnBody](this.chunk, this.offset, length));
434+
// 0, length are for backwards compatibility. See: https://github.com/creationix/http-parser-js/pull/98
435+
this.userCall()(this[kOnBody](this.chunk.slice(this.offset, this.end), 0, this.end - this.offset));
434436
this.offset = this.end;
435437
};
436438

437439
HTTPParser.prototype.BODY_SIZED = function () {
438440
var length = Math.min(this.end - this.offset, this.body_bytes);
439-
this.userCall()(this[kOnBody](this.chunk, this.offset, length));
441+
// 0, length are for backwards compatibility. See: https://github.com/creationix/http-parser-js/pull/98
442+
this.userCall()(this[kOnBody](this.chunk.slice(this.offset, this.offset + length), 0, length));
440443
this.offset += length;
441444
this.body_bytes -= length;
442445
if (!this.body_bytes) {

0 commit comments

Comments
 (0)