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kC,WAAZ,EAGxB,OAFA,EAAO,EAAK,KAAK,KAAK,aAAa,SACnC,EAAQ,IAAI,SAAS,EAAM,IAK7B,GAAgB,YAAZ,GAAqC,cAAZ,EAiB7B,EAAQ,IAAI,SAAS,EAAM,QAjB3B,CAGc,EAAI,KAAK,IAAI,aACrB,KAAK,QAAQ,IAGb,EADwB,IAAV,GAAX,EAAM,IACF,EAAK,KAAK,KAAK,cAAc,IAE7B,EAAK,KAAK,KAAK,iBAAiB,IAEzC,EAAQ,IAAI,SAAS,EAAM,GAAgB,GAG/C,CAG2C,IAG7C,cAAc,EAAK,EAAO,GAE9B,CArLA,QAAU,OAAO,QAAU,MA6L3B,MAAM,WAAa,GAAiB,MAAT,GAAyB,MAAT,GAAyB,MAAT,GAAyB,MAAT,GAAyB,MAAT,EAG3F,MAAM,QAAU,OAAO,QACvB,QAAQ,QAAU,QAClB,QAAQ,QAAU,QAClB,QAAQ,SAAW,SACnB,QAAQ,WAAa","file":"/npm/node-fetch-npm@2.0.4/src/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/node-fetch-npm@2.0.4/src/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","'use strict'\n\n/**\n * index.js\n *\n * a request API compatible with window.fetch\n */\n\nconst url = require('url')\nconst http = require('http')\nconst https = require('https')\nconst zlib = require('zlib')\nconst PassThrough = require('stream').PassThrough\n\nconst Body = require('./body.js')\nconst writeToStream = Body.writeToStream\nconst Response = require('./response')\nconst Headers = require('./headers')\nconst Request = require('./request')\nconst getNodeRequestOptions = Request.getNodeRequestOptions\nconst FetchError = require('./fetch-error')\nconst isURL = /^https?:/\n\n/**\n * Fetch function\n *\n * @param   Mixed    url   Absolute url or Request instance\n * @param   Object   opts  Fetch options\n * @return  Promise\n */\nexports = module.exports = fetch\nfunction fetch (uri, opts) {\n  // allow custom promise\n  if (!fetch.Promise) {\n    throw new Error('native promise missing, set fetch.Promise to your favorite alternative')\n  }\n\n  Body.Promise = fetch.Promise\n\n  // wrap http.request into fetch\n  return new fetch.Promise((resolve, reject) => {\n    // build request object\n    const request = new Request(uri, opts)\n    const options = getNodeRequestOptions(request)\n\n    const send = (options.protocol === 'https:' ? https : http).request\n\n    // http.request only support string as host header, this hack make custom host header possible\n    if (options.headers.host) {\n      options.headers.host = options.headers.host[0]\n    }\n\n    // send request\n    const req = send(options)\n    let reqTimeout\n\n    if (request.timeout) {\n      req.once('socket', socket => {\n        reqTimeout = setTimeout(() => {\n          req.abort()\n          reject(new FetchError(`network timeout at: ${request.url}`, 'request-timeout'))\n        }, request.timeout)\n      })\n    }\n\n    req.on('error', err => {\n      clearTimeout(reqTimeout)\n      reject(new FetchError(`request to ${request.url} failed, reason: ${err.message}`, 'system', err))\n    })\n\n    req.on('response', res => {\n      clearTimeout(reqTimeout)\n\n      // handle redirect\n      if (fetch.isRedirect(res.statusCode) && request.redirect !== 'manual') {\n        if (request.redirect === 'error') {\n          reject(new FetchError(`redirect mode is set to error: ${request.url}`, 'no-redirect'))\n          return\n        }\n\n        if (request.counter >= request.follow) {\n          reject(new FetchError(`maximum redirect reached at: ${request.url}`, 'max-redirect'))\n          return\n        }\n\n        if (!res.headers.location) {\n          reject(new FetchError(`redirect location header missing at: ${request.url}`, 'invalid-redirect'))\n          return\n        }\n\n        // Comment and logic below is used under the following license:\n        // Copyright (c) 2010-2012 Mikeal Rogers\n        // Licensed under the Apache License, Version 2.0 (the \"License\");\n        // you may not use this file except in compliance with the License.\n        // You may obtain a copy of the License at\n        // http://www.apache.org/licenses/LICENSE-2.0\n        // Unless required by applicable law or agreed to in writing,\n        // software distributed under the License is distributed on an \"AS\n        // IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n        // express or implied. See the License for the specific language\n        // governing permissions and limitations under the License.\n\n        // Remove authorization if changing hostnames (but not if just\n        // changing ports or protocols).  This matches the behavior of request:\n        // https://github.com/request/request/blob/b12a6245/lib/redirect.js#L134-L138\n        const resolvedUrl = url.resolve(request.url, res.headers.location)\n        let redirectURL = ''\n        if (!isURL.test(res.headers.location)) {\n          redirectURL = url.parse(resolvedUrl)\n        } else {\n          redirectURL = url.parse(res.headers.location)\n        }\n        if (url.parse(request.url).hostname !== redirectURL.hostname) {\n          request.headers.delete('authorization')\n        }\n\n        // per fetch spec, for POST request with 301/302 response, or any request with 303 response, use GET when following redirect\n        if (res.statusCode === 303 ||\n          ((res.statusCode === 301 || res.statusCode === 302) && request.method === 'POST')) {\n          request.method = 'GET'\n          request.body = null\n          request.headers.delete('content-length')\n        }\n\n        request.counter++\n\n        resolve(fetch(resolvedUrl, request))\n        return\n      }\n\n      // normalize location header for manual redirect mode\n      const headers = new Headers()\n      for (const name of Object.keys(res.headers)) {\n        if (Array.isArray(res.headers[name])) {\n          for (const val of res.headers[name]) {\n            headers.append(name, val)\n          }\n        } else {\n          headers.append(name, res.headers[name])\n        }\n      }\n      if (request.redirect === 'manual' && headers.has('location')) {\n        headers.set('location', url.resolve(request.url, headers.get('location')))\n      }\n\n      // prepare response\n      let body = res.pipe(new PassThrough())\n      const responseOptions = {\n        url: request.url,\n        status: res.statusCode,\n        statusText: res.statusMessage,\n        headers: headers,\n        size: request.size,\n        timeout: request.timeout\n      }\n\n      // HTTP-network fetch step 16.1.2\n      const codings = headers.get('Content-Encoding')\n\n      // HTTP-network fetch step 16.1.3: handle content codings\n\n      // in following scenarios we ignore compression support\n      // 1. compression support is disabled\n      // 2. HEAD request\n      // 3. no Content-Encoding header\n      // 4. no content response (204)\n      // 5. content not modified response (304)\n      if (!request.compress || request.method === 'HEAD' || codings === null || res.statusCode === 204 || res.statusCode === 304) {\n        resolve(new Response(body, responseOptions))\n        return\n      }\n\n      // Be less strict when decoding compressed responses, since sometimes\n      // servers send slightly invalid responses that are still accepted\n      // by common browsers.\n      // Always using Z_SYNC_FLUSH is what cURL does.\n      const zlibOptions = {\n        flush: zlib.Z_SYNC_FLUSH,\n        finishFlush: zlib.Z_SYNC_FLUSH\n      }\n\n      // for gzip\n      if (codings === 'gzip' || codings === 'x-gzip') {\n        body = body.pipe(zlib.createGunzip(zlibOptions))\n        resolve(new Response(body, responseOptions))\n        return\n      }\n\n      // for deflate\n      if (codings === 'deflate' || codings === 'x-deflate') {\n        // handle the infamous raw deflate response from old servers\n        // a hack for old IIS and Apache servers\n        const raw = res.pipe(new PassThrough())\n        raw.once('data', chunk => {\n          // see http://stackoverflow.com/questions/37519828\n          if ((chunk[0] & 0x0F) === 0x08) {\n            body = body.pipe(zlib.createInflate(zlibOptions))\n          } else {\n            body = body.pipe(zlib.createInflateRaw(zlibOptions))\n          }\n          resolve(new Response(body, responseOptions))\n        })\n        return\n      }\n\n      // otherwise, use response as-is\n      resolve(new Response(body, responseOptions))\n    })\n\n    writeToStream(req, request)\n  })\n};\n\n/**\n * Redirect code matching\n *\n * @param   Number   code  Status code\n * @return  Boolean\n */\nfetch.isRedirect = code => code === 301 || code === 302 || code === 303 || code === 307 || code === 308\n\n// expose Promise\nfetch.Promise = global.Promise\nexports.Headers = Headers\nexports.Request = Request\nexports.Response = Response\nexports.FetchError = FetchError\n"]}