{"version":3,"file":"node-request.cjs","sources":["../../src/middleware/defaultOptionsProcessor.ts","../../src/middleware/defaultOptionsValidator.ts","../../src/util/lowerCaseHeaders.ts","../../src/util/speedometer.ts","../../src/util/progress-stream.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 * Inlined variant of npm `speedometer` (https://github.com/mafintosh/speedometer),\n * MIT-licensed, Copyright (c) 2013 Mathias Buus.\n */\n\nlet tick = 1\nconst maxTick = 65535\nconst resolution = 4\nlet timer: ReturnType<typeof setInterval> | null = null\n\nconst inc = function () {\n  tick = (tick + 1) & maxTick\n}\n\nexport function speedometer(seconds: number) {\n  if (!timer) {\n    timer = setInterval(inc, (1000 / resolution) | 0)\n    if (timer.unref) timer.unref()\n  }\n\n  const size = resolution * (seconds || 5)\n  const buffer = [0]\n  let pointer = 1\n  let last = (tick - 1) & maxTick\n\n  return {\n    getSpeed: function (delta: number) {\n      let dist = (tick - last) & maxTick\n      if (dist > size) dist = size\n      last = tick\n\n      while (dist--) {\n        if (pointer === size) pointer = 0\n        buffer[pointer] = buffer[pointer === 0 ? size - 1 : pointer - 1]\n        pointer++\n      }\n\n      if (delta) buffer[pointer - 1] += delta\n\n      const top = buffer[pointer - 1]\n      const btm = buffer.length < size ? 0 : buffer[pointer === size ? 0 : pointer]\n\n      return buffer.length < resolution ? top : ((top - btm) * resolution) / buffer.length\n    },\n    clear: function () {\n      if (timer) {\n        clearInterval(timer)\n        timer = null\n      }\n    },\n  }\n}\n","/**\n * Inlined, reduced variant of npm `progress-stream` (https://github.com/freeall/progress-stream),\n * that fixes a bug with `content-length` header. BSD 2-Clause Simplified License,\n * Copyright (c) Tobias Baunbæk <freeall@gmail.com>.\n */\nimport type {Transform} from 'stream'\nimport through from 'through2'\n\nimport {speedometer} from './speedometer'\n\nexport interface Progress {\n  percentage: number\n  transferred: number\n  length: number\n  remaining: number\n  eta: number\n  runtime: number\n  delta: number\n  speed: number\n}\n\nexport interface ProgressStream extends Transform {\n  progress(): Progress\n}\n\nexport function progressStream(options: {time: number; length?: number}): ProgressStream {\n  let length = options.length || 0\n  let transferred = 0\n  let nextUpdate = Date.now() + options.time\n  let delta = 0\n  const speed = speedometer(5)\n  const startTime = Date.now()\n\n  const update = {\n    percentage: 0,\n    transferred: transferred,\n    length: length,\n    remaining: length,\n    eta: 0,\n    runtime: 0,\n    speed: 0,\n    delta: 0,\n  }\n\n  const emit = function (ended: boolean) {\n    update.delta = delta\n    update.percentage = ended ? 100 : length ? (transferred / length) * 100 : 0\n    update.speed = speed.getSpeed(delta)\n    update.eta = Math.round(update.remaining / update.speed)\n    update.runtime = Math.floor((Date.now() - startTime) / 1000)\n    nextUpdate = Date.now() + options.time\n\n    delta = 0\n\n    tr.emit('progress', update)\n  }\n\n  const write = function (\n    chunk: Buffer,\n    _enc: string,\n    callback: (err: Error | null, data?: Buffer) => void,\n  ) {\n    const len = chunk.length\n    transferred += len\n    delta += len\n    update.transferred = transferred\n    update.remaining = length >= transferred ? length - transferred : 0\n\n    if (Date.now() >= nextUpdate) emit(false)\n    callback(null, chunk)\n  }\n\n  const end = function (callback: (err?: Error | null) => void) {\n    emit(true)\n    speed.clear()\n    callback()\n  }\n\n  const tr = through({}, write, end) as ProgressStream\n  const onlength = function (newLength: number) {\n    length = newLength\n    update.length = length\n    update.remaining = length - update.transferred\n    tr.emit('length', length)\n  }\n\n  tr.on('pipe', function (stream) {\n    if (length > 0) return\n\n    // Support http module\n    if (\n      stream.readable &&\n      !('writable' in stream) &&\n      'headers' in stream &&\n      isRecord(stream.headers)\n    ) {\n      const contentLength =\n        typeof stream.headers['content-length'] === 'string'\n          ? parseInt(stream.headers['content-length'], 10)\n          : 0\n      return onlength(contentLength)\n    }\n\n    // Support streams with a length property\n    if ('length' in stream && typeof stream.length === 'number') {\n      return onlength(stream.length)\n    }\n\n    // Support request module\n    stream.on('response', function (res) {\n      if (!res || !res.headers) return\n      if (res.headers['content-encoding'] === 'gzip') return\n      if (res.headers['content-length']) {\n        return onlength(parseInt(res.headers['content-length']))\n      }\n    })\n  })\n\n  tr.progress = function () {\n    update.speed = speed.getSpeed(0)\n    update.eta = Math.round(update.remaining / update.speed)\n\n    return update\n  }\n\n  return tr\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n  return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n","/**\n * Code borrowed from https://github.com/request/request\n * Apache License 2.0\n */\n\nimport url, {type UrlWithStringQuery} from 'url'\n\nimport type {ProxyOptions, RequestOptions} from '../../types'\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: UrlWithStringQuery, noProxy: string) {\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) => {\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: UrlWithStringQuery): string | null {\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: UrlWithStringQuery) {\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: UrlWithStringQuery) {\n  const port = uri.port || (uri.protocol === 'https:' ? '443' : '80')\n  return `${uri.hostname}:${port}`\n}\n\nexport function rewriteUriForProxy(\n  reqOpts: RequestOptions & UrlWithStringQuery,\n  uri: UrlWithStringQuery,\n  proxy: UrlWithStringQuery | ProxyOptions,\n) {\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 = (\n    proxy.host ||\n    ('hostname' in proxy && proxy.hostname) ||\n    options.hostname ||\n    ''\n  ).replace(/:\\d+/, '')\n  options.port = proxy.port ? `${proxy.port}` : options.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: RequestOptions): UrlWithStringQuery | ProxyOptions | null {\n  const proxy =\n    typeof options.proxy === 'undefined' ? getProxyFromUri(url.parse(options.url)) : options.proxy\n\n  return typeof proxy === 'string' ? url.parse(proxy) : proxy || null\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 qs from 'querystring'\nimport {Readable, type Stream} from 'stream'\nimport url from 'url'\n\nimport type {RequestAdapter} from '../types'\nimport {lowerCaseHeaders} from '../util/lowerCaseHeaders'\nimport {progressStream} from '../util/progress-stream'\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: RequestAdapter = 'node'\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: http.IncomingMessage,\n  remoteAddress: string | undefined,\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 || 0,\n  statusMessage: res.statusMessage || '',\n  remoteAddress,\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] =\n      typeof proxy.auth === 'string'\n        ? proxy.auth.split(':').map((item) => qs.unescape(item))\n        : [proxy.auth.username, proxy.auth.password]\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    // Get the remote address from the socket, if available. After the stream is consumed, the socket might be closed, so we grab it here.\n    const remoteAddress = res.socket?.remoteAddress\n\n    if (options.stream) {\n      callback(null, reduceResponse(res, remoteAddress, 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, remoteAddress, 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.\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: 32, 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","tick","maxTick","timer","inc","progressStream","options","length","transferred","nextUpdate","Date","now","delta","speed","setInterval","unref","buffer","pointer","last","getSpeed","dist","resolution","size","top","btm","clear","clearInterval","speedometer","startTime","update","percentage","remaining","eta","runtime","emit","ended","Math","round","floor","tr","through","chunk","_enc","callback","len","onlength","newLength","on","stream","readable","Array","isArray","contentLength","parseInt","res","progress","formatHostname","hostname","parseNoProxyZone","zoneStr","zone","trim","zoneParts","split","port","hasPort","indexOf","uriParts","defaultProxyHeaderWhiteList","defaultProxyHeaderExclusiveList","isStream","pipe","adapter","NodeRequestError","Error","request","code","constructor","err","req","super","message","this","reduceResponse","remoteAddress","reqUrl","method","body","url","statusCode","statusMessage","exports","N","a","b","h","context","cb","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","channels","subscribe","proxy","noProxy","process","env","NO_PROXY","no_proxy","protocol","map","some","noProxyZone","isMatchedAt","hostnameMatched","uriInNoProxy","HTTP_PROXY","http_proxy","HTTPS_PROXY","https_proxy","getProxyFromUri","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","push","once","data","reduced","onError","destroy","removeListener","timeoutTimer","delays","hostHeader","getHeader","socketTimeoutHandler","e","connecting","timedOut","bodyStream","bodyIsStream","Readable","getProgressStream","end","p","query","searchParams","qIndex","URLSearchParams","base","slice","params","pair","append","splitUrl","entries","v","search","toUpperCase"],"mappings":"gyBAEA,MAAMA,WAAuBC,UAAc,MAA4C,gBAAtBA,U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