Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function getHttpResponseData (httpContentBuffer) {
const parser = new HTTPParser(HTTPParser.RESPONSE);
let httpData = {};
parser[HTTPParser.kOnMessageComplete] = noop;
parser[HTTPParser.kOnHeaders] = noop;
// Get headers and parse them to an object format for easier use
parser[HTTPParser.kOnHeadersComplete] = function (meta) {
const headerObject = {};
for (let i = 0; i < meta.headers.length; i += 2) {
headerObject[meta.headers[i]] = meta.headers[i + 1];
}
httpData = xtend(httpData, meta, {
headers: headerObject
});
this.opts = clone(opts)
this.opts.setupClient = this.opts.setupClient || noop
this.opts.pipelining = this.opts.pipelining || 1
this.opts.port = this.opts.port || 80
this.timeout = (this.opts.timeout || 10) * 1000
this.ipc = !!this.opts.socketPath
this.secure = this.opts.protocol === 'https:'
this.auth = this.opts.auth || null
if (this.secure && this.opts.port === 80) {
this.opts.port = 443
}
this.parser = new HTTPParser(HTTPParser.RESPONSE)
this.requestIterator = new RequestIterator(this.opts)
this.reqsMade = 0
// used for request limiting
this.responseMax = this.opts.responseMax
// used for rate limiting
this.reqsMadeThisSecond = 0
this.rate = this.opts.rate
// used for forcing reconnects
this.reconnectRate = this.opts.reconnectRate
this.resData = new Array(this.opts.pipelining)
for (let i = 0; i < this.opts.pipelining; i++) {
constructor (url, opts = {}) {
super()
if (!(url instanceof URL)) {
url = new URL(url)
}
this.url = url
// state machine, might need more states
this.closed = false
this.parser = new HTTPParser(HTTPParser.RESPONSE)
this[kTLSOpts] = opts.tls || opts.https
const endRequest = () => {
this.socket.write('\r\n', 'ascii')
this.socket.uncork()
this._needHeaders++
this[kRead]()
}
this.timeout = opts.timeout || 30000 // 30 seconds
this[kCallbacks] = []
this[kRequests] = []
const timerCb = () => {
if (this[kCallbacks].length > 0) {
function tickOnSocket(req, socket) {
var parser = parsers.alloc();
req.socket = socket;
req.connection = socket;
parser.reinitialize(HTTPParser.RESPONSE);
parser.socket = socket;
parser.incoming = null;
parser.outgoing = req;
req.parser = parser;
socket.parser = parser;
socket._httpMessage = req;
// Setup "drain" propagation.
httpSocketSetup(socket);
// Propagate headers limit from request object to parser
if (typeof req.maxHeadersCount === 'number') {
parser.maxHeaderPairs = req.maxHeadersCount << 1;
} else {
// Set default value because parser may be reused from FreeList
'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();
};
this._parser.onHeaderValue = function(b, start, length) {
'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();
};
this._parser.onHeaderValue = function(b, start, length) {
'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();
};
this._parser.onHeaderValue = function(b, start, length) {