Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// otherwise, destroy on timeout by default
if (self.timeout)
socket.setTimeout(self.timeout);
socket.on('timeout', function() {
var req = socket.parser && socket.parser.incoming;
var reqTimeout = req && !req.complete && req.emit('timeout', socket);
var res = socket._httpMessage;
var resTimeout = res && res.emit('timeout', socket);
var serverTimeout = self.emit('timeout', socket);
if (!reqTimeout && !resTimeout && !serverTimeout)
socket.destroy();
});
var parser = parsers.alloc();
parser.reinitialize(HTTPParser.REQUEST);
parser.socket = socket;
socket.parser = parser;
parser.incoming = null;
// Propagate headers limit from server instance to parser
if (typeof this.maxHeadersCount === 'number') {
parser.maxHeaderPairs = this.maxHeadersCount << 1;
} else {
// Set default value because parser may be reused from FreeList
parser.maxHeaderPairs = 2000;
}
socket.addListener('error', socketOnError);
socket.addListener('close', serverSocketCloseListener);
parser.onIncoming = parserOnIncoming;
socket.on('end', socketOnEnd);
function parseRequestBody(request) {
var parser = new HTTPParser(HTTPParser.REQUEST);
parser.body = '';
parser.bodyStart = 0;
parser[HTTPParser.kOnBody | 0] = function (b, start) {
if (!parser.bodyStart) {
parser.bodyStart = start;
}
parser.body = b;
};
if (typeof request === 'string') {
request = Buffer.from(request);
}
'use strict';
var NodeHTTPParser = require('http-parser-js').HTTPParser;
var VERSION = process.version.match(/[0-9]+/g).map(function(n) { return parseInt(n, 10) });
var TYPES = {
request: NodeHTTPParser.REQUEST || 'request',
response: NodeHTTPParser.RESPONSE || 'response'
};
var HttpParser = function(type) {
this._type = type;
this._parser = new NodeHTTPParser(TYPES[type]);
this._complete = false;
this.headers = {};
var current = null,
self = this;
this._parser.onHeaderField = function(b, start, length) {
current = b.toString('utf8', start, start + length).toLowerCase();
};
'use strict';
var NodeHTTPParser = require('http-parser-js').HTTPParser,
Buffer = require('safe-buffer').Buffer;
var TYPES = {
request: NodeHTTPParser.REQUEST || 'request',
response: NodeHTTPParser.RESPONSE || 'response'
};
var HttpParser = function(type) {
this._type = type;
this._parser = new NodeHTTPParser(TYPES[type]);
this._complete = false;
this.headers = {};
var current = null,
self = this;
this._parser.onHeaderField = function(b, start, length) {
current = b.toString('utf8', start, start + length).toLowerCase();
};
'use strict';
var NodeHTTPParser = require('http-parser-js').HTTPParser,
Buffer = require('safe-buffer').Buffer;
var TYPES = {
request: NodeHTTPParser.REQUEST || 'request',
response: NodeHTTPParser.RESPONSE || 'response'
};
var HttpParser = function(type) {
this._type = type;
this._parser = new NodeHTTPParser(TYPES[type]);
this._complete = false;
this.headers = {};
var current = null,
self = this;
this._parser.onHeaderField = function(b, start, length) {
current = b.toString('utf8', start, start + length).toLowerCase();
};