get-it
Version:
Generic HTTP request library for node, browsers and workers
1 lines • 40.5 kB
Source Map (JSON)
{"version":3,"file":"node-request.cjs","sources":["../../src/middleware/defaultOptionsProcessor.ts","../../src/middleware/defaultOptionsValidator.ts","../../src/util/lowerCaseHeaders.ts","../../src/request/node/proxy.ts","../../src/request/node/tunnel.ts","../../src/request/node-request.ts","../../src/request/node/simpleConcat.ts","../../src/request/node/timedOut.ts"],"sourcesContent":["import type {MiddlewareHooks, RequestOptions} from 'get-it'\n\nconst isReactNative = typeof navigator === 'undefined' ? false : navigator.product === 'ReactNative'\n\nconst defaultOptions = {timeout: isReactNative ? 60000 : 120000} satisfies Partial<RequestOptions>\n\n/** @public */\nexport const processOptions = function processOptions(opts) {\n const options = {\n ...defaultOptions,\n ...(typeof opts === 'string' ? {url: opts} : opts),\n } satisfies RequestOptions\n\n // Normalize timeouts\n options.timeout = normalizeTimeout(options.timeout)\n\n // Shallow-merge (override) existing query params\n if (options.query) {\n const {url, searchParams} = splitUrl(options.url)\n\n for (const [key, value] of Object.entries(options.query)) {\n if (value !== undefined) {\n if (Array.isArray(value)) {\n for (const v of value) {\n searchParams.append(key, v as string)\n }\n } else {\n searchParams.append(key, value as string)\n }\n }\n\n // Merge back params into url\n const search = searchParams.toString()\n if (search) {\n options.url = `${url}?${search}`\n }\n }\n }\n\n // Implicit POST if we have not specified a method but have a body\n options.method =\n options.body && !options.method ? 'POST' : (options.method || 'GET').toUpperCase()\n\n return options\n} satisfies MiddlewareHooks['processOptions']\n\n/**\n * Given a string URL, extracts the query string and URL from each other, and returns them.\n * Note that we cannot use the `URL` constructor because of old React Native versions which are\n * majorly broken and returns incorrect results:\n *\n * (`new URL('http://foo/?a=b').toString()` == 'http://foo/?a=b/')\n */\nfunction splitUrl(url: string): {url: string; searchParams: URLSearchParams} {\n const qIndex = url.indexOf('?')\n if (qIndex === -1) {\n return {url, searchParams: new URLSearchParams()}\n }\n\n const base = url.slice(0, qIndex)\n const qs = url.slice(qIndex + 1)\n\n // React Native's URL and URLSearchParams are broken, so passing a string to URLSearchParams\n // does not work, leading to an empty query string. For other environments, this should be enough\n if (!isReactNative) {\n return {url: base, searchParams: new URLSearchParams(qs)}\n }\n\n // Sanity-check; we do not know of any environment where this is the case,\n // but if it is, we should not proceed without giving a descriptive error\n if (typeof decodeURIComponent !== 'function') {\n throw new Error(\n 'Broken `URLSearchParams` implementation, and `decodeURIComponent` is not defined',\n )\n }\n\n const params = new URLSearchParams()\n for (const pair of qs.split('&')) {\n const [key, value] = pair.split('=')\n if (key) {\n params.append(decodeQueryParam(key), decodeQueryParam(value || ''))\n }\n }\n\n return {url: base, searchParams: params}\n}\n\nfunction decodeQueryParam(value: string): string {\n return decodeURIComponent(value.replace(/\\+/g, ' '))\n}\n\nfunction normalizeTimeout(time: RequestOptions['timeout']) {\n if (time === false || time === 0) {\n return false\n }\n\n if (time.connect || time.socket) {\n return time\n }\n\n const delay = Number(time)\n if (isNaN(delay)) {\n return normalizeTimeout(defaultOptions.timeout)\n }\n\n return {connect: delay, socket: delay}\n}\n","import type {MiddlewareHooks} from 'get-it'\n\nconst validUrl = /^https?:\\/\\//i\n\n/** @public */\nexport const validateOptions = function validateOptions(options) {\n if (!validUrl.test(options.url)) {\n throw new Error(`\"${options.url}\" is not a valid URL`)\n }\n} satisfies MiddlewareHooks['validateOptions']\n","export function lowerCaseHeaders(headers: any) {\n return Object.keys(headers || {}).reduce((acc, header) => {\n acc[header.toLowerCase()] = headers[header]\n return acc\n }, {} as any)\n}\n","/**\n * Code borrowed from https://github.com/request/request\n * Apache License 2.0\n */\n\nimport url from 'url'\n\nfunction formatHostname(hostname: string) {\n // canonicalize the hostname, so that 'oogle.com' won't match 'google.com'\n return hostname.replace(/^\\.*/, '.').toLowerCase()\n}\n\nfunction parseNoProxyZone(zoneStr: string) {\n const zone = zoneStr.trim().toLowerCase()\n\n const zoneParts = zone.split(':', 2)\n const zoneHost = formatHostname(zoneParts[0])\n const zonePort = zoneParts[1]\n const hasPort = zone.indexOf(':') > -1\n\n return {hostname: zoneHost, port: zonePort, hasPort: hasPort}\n}\n\nfunction uriInNoProxy(uri: any, noProxy: any) {\n const port = uri.port || (uri.protocol === 'https:' ? '443' : '80')\n const hostname = formatHostname(uri.hostname)\n const noProxyList = noProxy.split(',')\n\n // iterate through the noProxyList until it finds a match.\n return noProxyList.map(parseNoProxyZone).some((noProxyZone: any) => {\n const isMatchedAt = hostname.indexOf(noProxyZone.hostname)\n const hostnameMatched =\n isMatchedAt > -1 && isMatchedAt === hostname.length - noProxyZone.hostname.length\n\n if (noProxyZone.hasPort) {\n return port === noProxyZone.port && hostnameMatched\n }\n\n return hostnameMatched\n })\n}\n\nfunction getProxyFromUri(uri: any) {\n // Decide the proper request proxy to use based on the request URI object and the\n // environmental variables (NO_PROXY, HTTP_PROXY, etc.)\n // respect NO_PROXY environment variables (see: http://lynx.isc.org/current/breakout/lynx_help/keystrokes/environments.html)\n const noProxy = process.env['NO_PROXY'] || process.env['no_proxy'] || ''\n\n // if the noProxy is a wildcard then return null\n if (noProxy === '*') {\n return null\n }\n\n // if the noProxy is not empty and the uri is found return null\n if (noProxy !== '' && uriInNoProxy(uri, noProxy)) {\n return null\n }\n\n // Check for HTTP or HTTPS Proxy in environment, else default to null\n if (uri.protocol === 'http:') {\n return process.env['HTTP_PROXY'] || process.env['http_proxy'] || null\n }\n\n if (uri.protocol === 'https:') {\n return (\n process.env['HTTPS_PROXY'] ||\n process.env['https_proxy'] ||\n process.env['HTTP_PROXY'] ||\n process.env['http_proxy'] ||\n null\n )\n }\n\n // if none of that works, return null\n // (What uri protocol are you using then?)\n return null\n}\n\nfunction getHostFromUri(uri: any) {\n let host = uri.host\n\n // Drop :port suffix from Host header if known protocol.\n if (uri.port) {\n if (\n (uri.port === '80' && uri.protocol === 'http:') ||\n (uri.port === '443' && uri.protocol === 'https:')\n ) {\n host = uri.hostname\n }\n }\n\n return host\n}\n\nfunction getHostHeaderWithPort(uri: any) {\n const port = uri.port || (uri.protocol === 'https:' ? '443' : '80')\n return `${uri.hostname}:${port}`\n}\n\nexport function rewriteUriForProxy(reqOpts: any, uri: any, proxy: any) {\n const headers = reqOpts.headers || {}\n const options = Object.assign({}, reqOpts, {headers})\n headers.host = headers.host || getHostHeaderWithPort(uri)\n options.protocol = proxy.protocol || options.protocol\n options.hostname = proxy.host.replace(/:\\d+/, '')\n options.port = proxy.port\n options.host = getHostFromUri(Object.assign({}, uri, proxy))\n options.href = `${options.protocol}//${options.host}${options.path}`\n options.path = url.format(uri)\n return options\n}\n\nexport function getProxyOptions(options: any) {\n let proxy\n // eslint-disable-next-line no-prototype-builtins\n if (options.hasOwnProperty('proxy')) {\n proxy = options.proxy\n } else {\n const uri = url.parse(options.url)\n proxy = getProxyFromUri(uri)\n }\n\n return typeof proxy === 'string' ? url.parse(proxy) : proxy\n}\n","/**\n * Code borrowed from https://github.com/request/request\n * Modified to be less request-specific, more functional\n * Apache License 2.0\n */\nimport * as tunnel from 'tunnel-agent'\nimport url from 'url'\n\nconst uriParts = [\n 'protocol',\n 'slashes',\n 'auth',\n 'host',\n 'port',\n 'hostname',\n 'hash',\n 'search',\n 'query',\n 'pathname',\n 'path',\n 'href',\n]\n\nconst defaultProxyHeaderWhiteList = [\n 'accept',\n 'accept-charset',\n 'accept-encoding',\n 'accept-language',\n 'accept-ranges',\n 'cache-control',\n 'content-encoding',\n 'content-language',\n 'content-location',\n 'content-md5',\n 'content-range',\n 'content-type',\n 'connection',\n 'date',\n 'expect',\n 'max-forwards',\n 'pragma',\n 'referer',\n 'te',\n 'user-agent',\n 'via',\n]\n\nconst defaultProxyHeaderExclusiveList = ['proxy-authorization']\n\nexport function shouldEnable(options: any) {\n // Tunnel HTTPS by default. Allow the user to override this setting.\n\n // If user has specified a specific tunnel override...\n if (typeof options.tunnel !== 'undefined') {\n return Boolean(options.tunnel)\n }\n\n // If the destination is HTTPS, tunnel.\n const uri = url.parse(options.url)\n if (uri.protocol === 'https:') {\n return true\n }\n\n // Otherwise, do not use tunnel.\n return false\n}\n\nexport function applyAgent(opts: any = {}, proxy: any) {\n const options = Object.assign({}, opts)\n\n // Setup proxy header exclusive list and whitelist\n const proxyHeaderWhiteList = defaultProxyHeaderWhiteList\n .concat(options.proxyHeaderWhiteList || [])\n .map((header) => header.toLowerCase())\n\n const proxyHeaderExclusiveList = defaultProxyHeaderExclusiveList\n .concat(options.proxyHeaderExclusiveList || [])\n .map((header) => header.toLowerCase())\n\n // Get the headers we should send to the proxy\n const proxyHeaders = getAllowedProxyHeaders(options.headers, proxyHeaderWhiteList)\n proxyHeaders.host = constructProxyHost(options)\n\n // Reduce headers to the ones not exclusive for the proxy\n options.headers = Object.keys(options.headers || {}).reduce((headers, header) => {\n const isAllowed = proxyHeaderExclusiveList.indexOf(header.toLowerCase()) === -1\n if (isAllowed) {\n headers[header] = options.headers[header]\n }\n\n return headers\n }, {} as any)\n\n const tunnelFn = getTunnelFn(options, proxy)\n const tunnelOptions = constructTunnelOptions(options, proxy, proxyHeaders)\n options.agent = tunnelFn(tunnelOptions)\n\n return options\n}\n\nfunction getTunnelFn(options: any, proxy: any) {\n const uri = getUriParts(options)\n const tunnelFnName = constructTunnelFnName(uri, proxy)\n return tunnel[tunnelFnName]\n}\n\nfunction getUriParts(options: any) {\n return uriParts.reduce((uri, part) => {\n uri[part] = options[part]\n return uri\n }, {} as any)\n}\n\ntype UriProtocol = `http` | `https`\ntype ProxyProtocol = `Http` | `Https`\nfunction constructTunnelFnName(uri: any, proxy: any): `${UriProtocol}Over${ProxyProtocol}` {\n const uriProtocol = uri.protocol === 'https:' ? 'https' : 'http'\n const proxyProtocol = proxy.protocol === 'https:' ? 'Https' : 'Http'\n return `${uriProtocol}Over${proxyProtocol}`\n}\n\nfunction constructProxyHost(uri: any) {\n const port = uri.port\n const protocol = uri.protocol\n let proxyHost = `${uri.hostname}:`\n\n if (port) {\n proxyHost += port\n } else if (protocol === 'https:') {\n proxyHost += '443'\n } else {\n proxyHost += '80'\n }\n\n return proxyHost\n}\n\nfunction getAllowedProxyHeaders(headers: any, whiteList: any): any {\n return Object.keys(headers)\n .filter((header) => whiteList.indexOf(header.toLowerCase()) !== -1)\n .reduce((set: any, header: any) => {\n set[header] = headers[header]\n return set\n }, {})\n}\n\nfunction constructTunnelOptions(options: any, proxy: any, proxyHeaders: any) {\n return {\n proxy: {\n host: proxy.hostname,\n port: +proxy.port,\n proxyAuth: proxy.auth,\n headers: proxyHeaders,\n },\n headers: options.headers,\n ca: options.ca,\n cert: options.cert,\n key: options.key,\n passphrase: options.passphrase,\n pfx: options.pfx,\n ciphers: options.ciphers,\n rejectUnauthorized: options.rejectUnauthorized,\n secureOptions: options.secureOptions,\n secureProtocol: options.secureProtocol,\n }\n}\n","import decompressResponse from 'decompress-response'\nimport follow, {type FollowResponse, type RedirectableRequest} from 'follow-redirects'\nimport type {FinalizeNodeOptionsPayload, HttpRequest, MiddlewareResponse} from 'get-it'\nimport http from 'http'\nimport https from 'https'\nimport progressStream from 'progress-stream'\nimport qs from 'querystring'\nimport {Readable, type Stream} from 'stream'\nimport url from 'url'\n\nimport {lowerCaseHeaders} from '../util/lowerCaseHeaders'\nimport {getProxyOptions, rewriteUriForProxy} from './node/proxy'\nimport {concat} from './node/simpleConcat'\nimport {timedOut} from './node/timedOut'\nimport * as tunneling from './node/tunnel'\n\n/**\n * Taken from:\n * https://github.com/sindresorhus/is-stream/blob/fb8caed475b4107cee3c22be3252a904020eb2d4/index.js#L3-L6\n */\nconst isStream = (stream: any): stream is Stream =>\n stream !== null && typeof stream === 'object' && typeof stream.pipe === 'function'\n\n/** @public */\nexport const adapter = 'node' satisfies import('../types').RequestAdapter\n\nexport class NodeRequestError extends Error {\n request: http.ClientRequest\n code?: string | undefined\n\n constructor(err: NodeJS.ErrnoException, req: any) {\n super(err.message)\n this.request = req\n this.code = err.code\n }\n}\n\n// Reduce a fully fledged node-style response object to\n// something that works in both browser and node environment\nconst reduceResponse = (\n res: any,\n reqUrl: string,\n method: string,\n body: any,\n): MiddlewareResponse => ({\n body,\n url: reqUrl,\n method: method,\n headers: res.headers,\n statusCode: res.statusCode,\n statusMessage: res.statusMessage,\n})\n\nexport const httpRequester: HttpRequest = (context, cb) => {\n const {options} = context\n const uri = Object.assign({}, url.parse(options.url))\n\n if (typeof fetch === 'function' && options.fetch) {\n const controller = new AbortController()\n const reqOpts = context.applyMiddleware('finalizeOptions', {\n ...uri,\n method: options.method,\n headers: {\n ...(typeof options.fetch === 'object' && options.fetch.headers\n ? lowerCaseHeaders(options.fetch.headers)\n : {}),\n ...lowerCaseHeaders(options.headers),\n },\n maxRedirects: options.maxRedirects,\n }) as FinalizeNodeOptionsPayload\n const fetchOpts = {\n credentials: options.withCredentials ? 'include' : 'omit',\n ...(typeof options.fetch === 'object' ? options.fetch : {}),\n method: reqOpts.method,\n headers: reqOpts.headers,\n body: options.body,\n signal: controller.signal,\n } satisfies RequestInit\n\n // Allow middleware to inject a response, for instance in the case of caching or mocking\n const injectedResponse = context.applyMiddleware('interceptRequest', undefined, {\n adapter,\n context,\n })\n\n // If middleware injected a response, treat it as we normally would and return it\n // Do note that the injected response has to be reduced to a cross-environment friendly response\n if (injectedResponse) {\n const cbTimer = setTimeout(cb, 0, null, injectedResponse)\n const cancel = () => clearTimeout(cbTimer)\n return {abort: cancel}\n }\n\n const request = fetch(options.url, fetchOpts)\n\n // Let middleware know we're about to do a request\n context.applyMiddleware('onRequest', {options, adapter, request, context})\n\n request\n .then(async (res) => {\n const body = options.rawBody ? res.body : await res.text()\n\n const headers = {} as Record<string, string>\n res.headers.forEach((value, key) => {\n headers[key] = value\n })\n\n cb(null, {\n body,\n url: res.url,\n method: options.method!,\n headers,\n statusCode: res.status,\n statusMessage: res.statusText,\n })\n })\n .catch((err) => {\n if (err.name == 'AbortError') return\n cb(err)\n })\n\n return {abort: () => controller.abort()}\n }\n\n const bodyType = isStream(options.body) ? 'stream' : typeof options.body\n if (\n bodyType !== 'undefined' &&\n bodyType !== 'stream' &&\n bodyType !== 'string' &&\n !Buffer.isBuffer(options.body)\n ) {\n throw new Error(`Request body must be a string, buffer or stream, got ${bodyType}`)\n }\n\n const lengthHeader: any = {}\n if (options.bodySize) {\n lengthHeader['content-length'] = options.bodySize\n } else if (options.body && bodyType !== 'stream') {\n lengthHeader['content-length'] = Buffer.byteLength(options.body)\n }\n\n // Make sure callback is not called in the event of a cancellation\n let aborted = false\n const callback = (err: Error | null, res?: MiddlewareResponse) => !aborted && cb(err, res)\n context.channels.abort.subscribe(() => {\n aborted = true\n })\n\n // Create a reduced subset of options meant for the http.request() method\n let reqOpts: any = Object.assign({}, uri, {\n method: options.method,\n headers: Object.assign({}, lowerCaseHeaders(options.headers), lengthHeader),\n maxRedirects: options.maxRedirects,\n })\n\n // Figure out proxying/tunnel options\n const proxy = getProxyOptions(options)\n const tunnel = proxy && tunneling.shouldEnable(options)\n\n // Allow middleware to inject a response, for instance in the case of caching or mocking\n const injectedResponse = context.applyMiddleware('interceptRequest', undefined, {\n adapter,\n context,\n })\n\n // If middleware injected a response, treat it as we normally would and return it\n // Do note that the injected response has to be reduced to a cross-environment friendly response\n if (injectedResponse) {\n const cbTimer = setImmediate(callback, null, injectedResponse)\n const abort = () => clearImmediate(cbTimer)\n return {abort}\n }\n\n // We're using the follow-redirects module to transparently follow redirects\n if (options.maxRedirects !== 0) {\n reqOpts.maxRedirects = options.maxRedirects || 5\n }\n\n // Apply currect options for proxy tunneling, if enabled\n if (proxy && tunnel) {\n reqOpts = tunneling.applyAgent(reqOpts, proxy)\n } else if (proxy && !tunnel) {\n reqOpts = rewriteUriForProxy(reqOpts, uri, proxy)\n }\n\n // Handle proxy authorization if present\n if (!tunnel && proxy && proxy.auth && !reqOpts.headers['proxy-authorization']) {\n const [username, password] = proxy.auth.username\n ? [proxy.auth.username, proxy.auth.password]\n : proxy.auth.split(':').map((item: any) => qs.unescape(item))\n\n const auth = Buffer.from(`${username}:${password}`, 'utf8')\n const authBase64 = auth.toString('base64')\n reqOpts.headers['proxy-authorization'] = `Basic ${authBase64}`\n }\n\n // Figure out transport (http/https, forwarding/non-forwarding agent)\n const transport = getRequestTransport(reqOpts, proxy, tunnel)\n if (typeof options.debug === 'function' && proxy) {\n options.debug(\n 'Proxying using %s',\n reqOpts.agent ? 'tunnel agent' : `${reqOpts.host}:${reqOpts.port}`,\n )\n }\n\n // See if we should try to request a compressed response (and decompress on return)\n const tryCompressed = reqOpts.method !== 'HEAD'\n if (tryCompressed && !reqOpts.headers['accept-encoding'] && options.compress !== false) {\n reqOpts.headers['accept-encoding'] =\n // Workaround Bun not supporting brotli: https://github.com/oven-sh/bun/issues/267\n typeof Bun !== 'undefined' ? 'gzip, deflate' : 'br, gzip, deflate'\n }\n\n let _res: http.IncomingMessage | undefined\n const finalOptions = context.applyMiddleware(\n 'finalizeOptions',\n reqOpts,\n ) as FinalizeNodeOptionsPayload\n const request = transport.request(finalOptions, (response) => {\n const res = tryCompressed ? decompressResponse(response) : response\n _res = res\n const resStream = context.applyMiddleware('onHeaders', res, {\n headers: response.headers,\n adapter,\n context,\n })\n\n // On redirects, `responseUrl` is set\n const reqUrl = 'responseUrl' in response ? response.responseUrl : options.url\n\n if (options.stream) {\n callback(null, reduceResponse(res, reqUrl, reqOpts.method, resStream))\n return\n }\n\n // Concatenate the response body, then parse the response with middlewares\n concat(resStream, (err: any, data: any) => {\n if (err) {\n return callback(err)\n }\n\n const body = options.rawBody ? data : data.toString()\n const reduced = reduceResponse(res, reqUrl, reqOpts.method, body)\n return callback(null, reduced)\n })\n })\n\n function onError(err: NodeJS.ErrnoException) {\n // HACK: If we have a socket error, and response has already been assigned this means\n // that a response has already been sent. According to node.js docs, this is\n // will result in the response erroring with an error code of 'ECONNRESET'.\n // We first destroy the response, then the request, with the same error. This way the\n // error is forwarded to both the response and the request.\n // See the event order outlined here https://nodejs.org/api/http.html#httprequesturl-options-callback for how node.js handles the different scenarios.\n if (_res) _res.destroy(err)\n request.destroy(err)\n }\n\n request.once('socket', (socket: NodeJS.Socket) => {\n socket.once('error', onError)\n request.once('response', (response) => {\n response.once('end', () => {\n socket.removeListener('error', onError)\n })\n })\n })\n\n request.once('error', (err: NodeJS.ErrnoException) => {\n if (_res) return\n // The callback has already been invoked. Any error should be sent to the response.\n callback(new NodeRequestError(err, request))\n })\n\n if (options.timeout) {\n timedOut(request, options.timeout)\n }\n\n // Cheating a bit here; since we're not concerned about the \"bundle size\" in node,\n // and modifying the body stream would be sorta tricky, we're just always going\n // to put a progress stream in the middle here. Note that\n const {bodyStream, progress} = getProgressStream(options)\n\n // Let middleware know we're about to do a request\n context.applyMiddleware('onRequest', {options, adapter, request, context, progress})\n\n if (bodyStream) {\n bodyStream.pipe(request)\n } else {\n request.end(options.body)\n }\n\n return {abort: () => request.abort()}\n}\n\nfunction getProgressStream(options: any) {\n if (!options.body) {\n return {}\n }\n\n const bodyIsStream = isStream(options.body)\n const length = options.bodySize || (bodyIsStream ? null : Buffer.byteLength(options.body))\n if (!length) {\n return bodyIsStream ? {bodyStream: options.body} : {}\n }\n\n const progress = progressStream({time: 16, length})\n const bodyStream = bodyIsStream ? options.body : Readable.from(options.body)\n return {bodyStream: bodyStream.pipe(progress), progress}\n}\n\nfunction getRequestTransport(\n reqOpts: any,\n proxy: any,\n tunnel: any,\n): {\n request: (\n options: any,\n callback: (response: http.IncomingMessage | (http.IncomingMessage & FollowResponse)) => void,\n ) => http.ClientRequest | RedirectableRequest<http.ClientRequest, http.IncomingMessage>\n} {\n const isHttpsRequest = reqOpts.protocol === 'https:'\n const transports =\n reqOpts.maxRedirects === 0\n ? {http: http, https: https}\n : {http: follow.http, https: follow.https}\n\n if (!proxy || tunnel) {\n return isHttpsRequest ? transports.https : transports.http\n }\n\n // Assume the proxy is an HTTPS proxy if port is 443, or if there is a\n // `protocol` option set that starts with https\n let isHttpsProxy = proxy.port === 443\n if (proxy.protocol) {\n isHttpsProxy = /^https:?/.test(proxy.protocol)\n }\n\n return isHttpsProxy ? transports.https : transports.http\n}\n","/*! simple-concat. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */\nexport function concat(stream: any, cb: any) {\n const chunks: any = []\n stream.on('data', function (chunk: any) {\n chunks.push(chunk)\n })\n stream.once('end', function () {\n if (cb) cb(null, Buffer.concat(chunks))\n cb = null\n })\n stream.once('error', function (err: any) {\n if (cb) cb(err)\n cb = null\n })\n}\n","// Copied from `@sanity/timed-out`\n\nimport type {IncomingMessage} from 'node:http'\nimport type {Socket} from 'node:net'\n\nexport function timedOut(req: any, time: any) {\n if (req.timeoutTimer) {\n return req\n }\n\n const delays = isNaN(time) ? time : {socket: time, connect: time}\n const hostHeader = req.getHeader('host')\n const host = hostHeader ? ' to ' + hostHeader : ''\n\n if (delays.connect !== undefined) {\n req.timeoutTimer = setTimeout(function timeoutHandler() {\n const e: NodeJS.ErrnoException = new Error('Connection timed out on request' + host)\n e.code = 'ETIMEDOUT'\n req.destroy(e)\n }, delays.connect)\n }\n\n // Clear the connection timeout timer once a socket is assigned to the\n // request and is connected.\n req.on('socket', function assign(socket: Socket) {\n // Socket may come from Agent pool and may be already connected.\n if (!socket.connecting) {\n connect(socket)\n return\n }\n\n socket.once('connect', () => connect(socket))\n })\n\n function clear() {\n if (req.timeoutTimer) {\n clearTimeout(req.timeoutTimer)\n req.timeoutTimer = null\n }\n }\n\n function connect(socket: Socket) {\n clear()\n\n if (delays.socket !== undefined) {\n const socketTimeoutHandler = () => {\n const e: NodeJS.ErrnoException = new Error('Socket timed out on request' + host)\n e.code = 'ESOCKETTIMEDOUT'\n socket.destroy(e)\n }\n\n socket.setTimeout(delays.socket, socketTimeoutHandler)\n req.once('response', (response: IncomingMessage) => {\n response.once('end', () => {\n socket.removeListener('timeout', socketTimeoutHandler)\n })\n })\n }\n }\n\n return req.on('error', clear)\n}\n"],"names":["isReactNative","navigator","product","defaultOptions","timeout","decodeQueryParam","value","decodeURIComponent","replace","normalizeTimeout","time","connect","socket","delay","Number","isNaN","validUrl","lowerCaseHeaders","headers","Object","keys","reduce","acc","header","toLowerCase","formatHostname","hostname","parseNoProxyZone","zoneStr","zone","trim","zoneParts","split","port","hasPort","indexOf","uriParts","defaultProxyHeaderWhiteList","defaultProxyHeaderExclusiveList","isStream","stream","pipe","adapter","NodeRequestError","Error","request","code","constructor","err","req","super","message","this","reduceResponse","res","reqUrl","method","body","url","statusCode","statusMessage","exports","N","a","h","context","cb","options","uri","assign","parse","fetch","controller","AbortController","reqOpts","applyMiddleware","maxRedirects","fetchOpts","credentials","withCredentials","signal","injectedResponse","cbTimer","setTimeout","abort","clearTimeout","then","async","rawBody","text","forEach","key","status","statusText","catch","name","bodyType","Buffer","isBuffer","lengthHeader","bodySize","byteLength","aborted","callback","channels","subscribe","proxy","hasOwnProperty","noProxy","process","env","NO_PROXY","no_proxy","protocol","map","some","noProxyZone","isMatchedAt","hostnameMatched","length","uriInNoProxy","HTTP_PROXY","http_proxy","HTTPS_PROXY","https_proxy","getProxyFromUri","default","getProxyOptions","tunnel","tunneling.shouldEnable","setImmediate","clearImmediate","opts","proxyHeaderWhiteList","concat","proxyHeaderExclusiveList","proxyHeaders","whiteList","filter","set","host","proxyHost","constructProxyHost","tunnelFn","part","getUriParts","tunnelFnName","constructTunnelFnName","getTunnelFn","tunnelOptions","proxyAuth","auth","ca","cert","passphrase","pfx","ciphers","rejectUnauthorized","secureOptions","secureProtocol","constructTunnelOptions","agent","tunneling.applyAgent","getHostHeaderWithPort","getHostFromUri","href","path","format","rewriteUriForProxy","username","password","item","qs","unescape","authBase64","from","toString","transport","isHttpsRequest","transports","http","https","follow","isHttpsProxy","test","getRequestTransport","debug","tryCompressed","_res","compress","Bun","finalOptions","response","decompressResponse","resStream","responseUrl","chunks","on","chunk","push","once","data","reduced","onError","destroy","removeListener","timeoutTimer","delays","hostHeader","getHeader","clear","socketTimeoutHandler","e","connecting","timedOut","bodyStream","progress","bodyIsStream","progressStream","Readable","getProgressStream","end","p","query","searchParams","qIndex","URLSearchParams","base","slice","params","pair","append","splitUrl","entries","Array","isArray","v","search","toUpperCase"],"mappings":"yyBAEA,MAAMA,WAAuBC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