http-parser-js
Advanced tools
Comparing version 0.5.8 to 0.5.9
/*jshint node:true */ | ||
var assert = require('assert'); | ||
exports.HTTPParser = HTTPParser; | ||
function HTTPParser(type) { | ||
assert.ok(type === HTTPParser.REQUEST || type === HTTPParser.RESPONSE || type === undefined); | ||
if (type !== undefined && type !== HTTPParser.REQUEST && type !== HTTPParser.RESPONSE) { | ||
throw new Error('type must be REQUEST or RESPONSE'); | ||
} | ||
if (type === undefined) { | ||
@@ -16,3 +16,5 @@ // Node v12+ | ||
HTTPParser.prototype.initialize = function (type, async_resource) { | ||
assert.ok(type === HTTPParser.REQUEST || type === HTTPParser.RESPONSE); | ||
if (type !== HTTPParser.REQUEST && type !== HTTPParser.RESPONSE) { | ||
throw new Error('type must be REQUEST or RESPONSE'); | ||
} | ||
this.type = type; | ||
@@ -102,2 +104,3 @@ this.state = type + '_LINE'; | ||
HTTPParser.prototype.resume = | ||
HTTPParser.prototype.remove = | ||
HTTPParser.prototype.free = function () {}; | ||
@@ -397,3 +400,4 @@ HTTPParser.prototype._compatMode0_11 = false; | ||
var length = Math.min(this.end - this.offset, this.body_bytes); | ||
this.userCall()(this[kOnBody](this.chunk, this.offset, length)); | ||
// 0, length are for backwards compatibility. See: https://github.com/creationix/http-parser-js/pull/98 | ||
this.userCall()(this[kOnBody](this.chunk.slice(this.offset, this.offset + length), 0, length)); | ||
this.offset += length; | ||
@@ -411,3 +415,5 @@ this.body_bytes -= length; | ||
} | ||
assert.equal(line, ''); | ||
if (line !== '') { | ||
throw new Error('Expected empty line'); | ||
} | ||
this.state = 'BODY_CHUNKHEAD'; | ||
@@ -432,4 +438,4 @@ }; | ||
HTTPParser.prototype.BODY_RAW = function () { | ||
var length = this.end - this.offset; | ||
this.userCall()(this[kOnBody](this.chunk, this.offset, length)); | ||
// 0, length are for backwards compatibility. See: https://github.com/creationix/http-parser-js/pull/98 | ||
this.userCall()(this[kOnBody](this.chunk.slice(this.offset, this.end), 0, this.end - this.offset)); | ||
this.offset = this.end; | ||
@@ -440,3 +446,4 @@ }; | ||
var length = Math.min(this.end - this.offset, this.body_bytes); | ||
this.userCall()(this[kOnBody](this.chunk, this.offset, length)); | ||
// 0, length are for backwards compatibility. See: https://github.com/creationix/http-parser-js/pull/98 | ||
this.userCall()(this[kOnBody](this.chunk.slice(this.offset, this.offset + length), 0, length)); | ||
this.offset += length; | ||
@@ -443,0 +450,0 @@ this.body_bytes -= length; |
{ | ||
"name": "http-parser-js", | ||
"version": "0.5.8", | ||
"version": "0.5.9", | ||
"description": "A pure JS HTTP parser for node.", | ||
@@ -5,0 +5,0 @@ "main": "http-parser.js", |
26340
592