Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (!this._agent) {
if (this._debug) {
console.log('> [debug] re-initializing agent')
}
this._initAgent()
}
const { body } = opts
if (this._agent) {
opts.agent = this._agent
}
if (body && typeof body === 'object' && typeof body.pipe !== 'function') {
opts.headers['Content-Type'] = 'application/json'
if (shouldUseHttp2(this)) {
opts.body = new JsonBody(body)
} else {
opts.body = JSON.stringify(body)
}
}
if(shouldUseHttp2(this) && body && typeof body === 'object' && typeof body.pipe === 'function') {
opts.body = new StreamBody(body)
}
if (!shouldUseHttp2(this) && opts.body && typeof body.pipe !== 'function') {
opts.headers['Content-Length'] = Buffer.byteLength(opts.body)
}
const handleCompleted = async (res) => {
currentContext.ongoingFetches--;
if(currentContext !== this._currContext && currentContext.ongoingFetches <= 0) {
._currContext.ongoingFetches}`
);
if (!this._agent) {
debug('Re-initializing agent');
this._initAgent();
}
const { body } = opts;
if (this._agent) {
opts.agent = this._agent;
}
if (body && typeof body === 'object' && typeof body.pipe !== 'function') {
opts.headers['Content-Type'] = 'application/json';
opts.body = new JsonBody(body);
}
if (
body &&
typeof body === 'object' &&
typeof body.pipe === 'function'
) {
opts.body = new StreamBody(body);
}
const handleCompleted = async res => {
currentContext.ongoingFetches--;
if (
currentContext !== this._currContext &&
currentContext.ongoingFetches <= 0
) {