Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
uri = `${ registry.trim().replace(/\/?$/g, '') }/${ uri.trim().replace(/^\//, '') }` } const method = opts.method || /* istanbul ignore next: default set in figgy pudding config */ 'GET' // through that takes into account the scope, the prefix of `uri`, etc const startTime = Date.now() const headers = getHeaders(registry, uri, opts) let body = opts.body const bodyIsStream = Minipass.isStream(body) const bodyIsPromise = body && typeof body === 'object' && typeof body.then === 'function' if (body && !bodyIsStream && !bodyIsPromise && typeof body !== 'string' && !Buffer.isBuffer(body)) { headers['content-type'] = headers['content-type'] || 'application/json' body = JSON.stringify(body) } else if (body && !headers['content-type']) { headers['content-type'] = 'application/octet-stream' } if (opts.gzip) { headers['content-encoding'] = 'gzip' if (bodyIsStream) { const gz = new zlib.Gzip() body.on('error', /* istanbul ignore next: unlikely and hard to test */.then((res) => { if (opts.integrity) { res = remoteFetchHandleIntegrity(res, opts.integrity) } res.headers.set('x-fetch-attempts', attemptNum) const isStream = Minipass.isStream(req.body) if (opts.cacheManager) { const isMethodGetHead = ( req.method === 'GET' || req.method === 'HEAD' ) const isCachable = ( opts.cache !== 'no-store' && isMethodGetHead && makePolicy(req, res).storable() && res.status === 200 // No other statuses should be stored! ) if (isCachable) { return opts.cacheManager.put(req, res, opts).then((res) => { t.equal(res.status, 200, 'successful status code') t.ok(Minipass.isStream(res.body), 'body is a stream') return res.buffer() }) .then((buf) => {