Socket
Socket
Sign inDemoInstall

http-parser-js

Package Overview
Dependencies
Maintainers
2
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-parser-js - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

55

http-parser.js

@@ -23,2 +23,5 @@ /*jshint node:true */

this.encoding = null;
this.connection = null;
this.body_bytes = null;
this.headResponse = null;
}

@@ -32,2 +35,3 @@ HTTPParser.REQUEST = "REQUEST";

BODY_RAW: true,
BODY_SIZED: true,
BODY_CHUNK: true

@@ -45,3 +49,3 @@ };

this.end = offset + length;
while (this.offset < this.end) {
while (this.offset < this.end && this.state !== "UNINITIALIZED") {
var state = this.state;

@@ -91,3 +95,3 @@ this[state]();

var responseExp = /^HTTP\/([0-9]).([0-9]) (\d+) (\w+)$/;
var responseExp = /^HTTP\/([0-9]).([0-9]) (\d+) ([^\n\r]+)$/;
HTTPParser.prototype.RESPONSE_LINE = function () {

@@ -99,6 +103,13 @@ var line = this.consumeLine();

var match = responseExp.exec(line);
this.info.versionMajor = match[1];
this.info.versionMinor = match[2];
this.info.statusCode = Number(match[3]);
var versionMajor = this.info.versionMajor = match[1];
var versionMinor = this.info.versionMinor = match[2];
var statusCode = this.info.statusCode = Number(match[3]);
this.info.statusMsg = match[4];
// Implied zero length.
if ((statusCode / 100 | 0) === 1 || statusCode === 204 || statusCode === 304) {
this.body_bytes = 0;
}
if (versionMajor === '1' && versionMinor === '0') {
this.connection = 'close';
}
this.state = "HEADER";

@@ -114,9 +125,19 @@ };

var match = headerExp.exec(line);
var k = match && match[1].toLowerCase();
var k = match && match[1];
var v = match && match[2];
if (k) { // skip empty string (malformed header)
if (!this.preserveCase) {
k = k.toLowerCase();
}
this.info.headers.push(k);
this.info.headers.push(v);
if (this.preserveCase) {
k = k.toLowerCase();
}
if (k === 'transfer-encoding') {
this.encoding = v;
} else if (k === 'content-length') {
this.body_bytes = parseInt(v, 10);
} else if (k === 'connection') {
this.connection = v;
}

@@ -128,6 +149,13 @@ }

this.onHeadersComplete(this.info);
if (this.encoding === 'chunked') {
// Set ``this.headResponse = true;`` to ignore Content-Length.
if (this.headResponse) {
this.onMessageComplete();
this.state = 'UNINITIALIZED';
} else if (this.encoding === 'chunked') {
this.state = "BODY_CHUNKHEAD";
} else if (this.body_bytes === null) {
//if (this.connection !== 'close') throw new Error('Unkown body length');
this.state = "BODY_RAW";
} else {
this.state = "BODY_RAW";
this.state = "BODY_SIZED";
}

@@ -189,1 +217,12 @@ }

};
HTTPParser.prototype.BODY_SIZED = function () {
var length = Math.min(this.end - this.offset, this.body_bytes);
this.onBody(this.chunk, this.offset, length);
this.offset += length;
this.body_bytes -= length;
if (!this.body_bytes) {
this.onMessageComplete();
this.state = 'UNINITIALIZED';
}
};

8

package.json
{
"name": "http-parser-js",
"version": "0.1.0",
"version": "0.2.0",
"description": "A pure JS HTTP parser for node.",

@@ -16,4 +16,8 @@ "main": "http-parser.js",

],
"author": "Tim Caswell",
"author": "Tim Caswell (https://github.com/creationix)",
"contributors": [
"Jimb Esser (https://github.com/Jimbly)",
"Lawrence Rowe (https://github.com/lrowe)"
],
"license": "MIT"
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc