Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
endRequest()
})
}
return
}
endRequest()
})
this.pipelining = opts.pipelining || 1
this[kQueue].drain = () => {
this.emit('drain')
}
this.parser[HTTPParser.kOnHeaders] = () => {}
this.parser[HTTPParser.kOnHeadersComplete] = ({ statusCode, headers }) => {
// TODO move this[kCallbacks] from being an array. The array allocation
// is showing up in the flamegraph.
const cb = this[kCallbacks].shift()
this._needHeaders--
this._lastBody = new Readable({ read: this[kRead].bind(this) })
this._lastBody.push = this[kRequests].shift().wrapSimple(this._lastBody, this._lastBody.push)
cb(null, {
statusCode,
headers: parseHeaders(headers),
body: this._lastBody
})
if (this.closed && this[kQueue].length() === 0) {
this.destroy()
// timeout has already occured, need to set a new timeoutTicker
this.timeoutTicker = retimer(handleTimeout, this.timeout)
this._connect()
}
if (this.rate) {
this.rateInterval = setInterval(() => {
this.reqsMadeThisSecond = 0
if (this.paused) this._doRequest(this.cer)
this.paused = false
}, 1000)
}
this.timeoutTicker = retimer(handleTimeout, this.timeout)
this.parser[HTTPParser.kOnHeaders] = () => {}
this.parser[HTTPParser.kOnHeadersComplete] = (opts) => {
this.emit('headers', opts)
this.resData[this.cer].headers = opts
}
this.parser[HTTPParser.kOnBody] = (body) => {
this.emit('body', body)
}
this.parser[HTTPParser.kOnMessageComplete] = () => {
const end = process.hrtime(this.resData[this.cer].startTime)
const responseTime = end[0] * 1e3 + end[1] / 1e6
this.emit('response', this.resData[this.cer].headers.statusCode, this.resData[this.cer].bytes, responseTime)
this.resData[this.cer].bytes = 0
if (!this.destroyed && this.reconnectRate && this.reqsMade % this.reconnectRate === 0) {
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
});
};
// The below function can fire multiple times for "transfer-encoding: chunked"
// We need to build up the body in a buffer to ensure we capture it entirely