{"version":3,"sources":["jsdelivr-header.js","/npm/undici-proxy@0.3.0/lib/index.js"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,ACNA,MAAM,QAAU,QAAQ,YAClB,OAAE,OAAM,KAAE,MAAS,QAAQ,WAC3B,KAAE,MAAS,QAAQ,UAEnB,mBAAqB,CACzB,aACA,aACA,qBACA,sBACA,KACA,UACA,oBACA,WAMF,SAAS,MAAM,GACb,MAAM,EAAO,aAAe,KAAO,EAAM,IAAI,KAAK,GAGlD,SAAS,EAAS,EAAK,EAAK,GAC1B,EAAK,OACH,CACE,OACE,EACF,OACA,KAAM,EAAI,IACV,QAAS,KAAK,EAAI,QAAS,UAAW,oBACtC,KAAM,EACN,OAAQ,IAEV,UAAU,WAAE,EAAU,QAAE,EAAO,OAAE,IAE/B,OADsD,EAC3C,UAAU,EAAY,KAAK,KAAY,oBACpD,IACA,SAAU,GAAK,OAAE,EAAM,SAAE,IACvB,GAAI,EAAK,OAAO,EAAK,OAAO,EAAK,CAAE,WAAY,OACO,EAClD,YAAY,EAClB,GAEJ,CAWA,OAAO,OAAO,EAAU,CAAE,OAR1B,YAC8D,GAE5D,OAAO,UACJ,IAAI,GACJ,UAAU,EACf,GAGF,CAEA,OAAO,QAAU","file":"/npm/undici-proxy@0.3.0/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/undici-proxy@0.3.0/lib/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","const express = require(\"express\");\nconst { assign, omit } = require(\"lodash\");\nconst { Pool } = require(\"undici\");\n\nconst HOP_BY_HOP_HEADERS = [\n  \"connection\",\n  \"keep-alive\",\n  \"proxy-authenticate\",\n  \"proxy-authorization\",\n  \"te\",\n  \"trailer\",\n  \"transfer-encoding\",\n  \"upgrade\",\n];\n\n/**\n * @param {string | URL | Pool} url\n */\nfunction proxy(url) {\n  const pool = url instanceof Pool ? url : new Pool(url);\n\n  /** @type {express.RequestHandler} */\n  function listener(req, res, next) {\n    pool.stream(\n      {\n        method: /** @type {import(\"undici\").Dispatcher.HttpMethod} */ (\n          req.method\n        ),\n        path: req.url,\n        headers: omit(req.headers, \"host\", ...HOP_BY_HOP_HEADERS),\n        body: req,\n        opaque: res,\n      },\n      function ({ statusCode, headers, opaque }) {\n        const res = /** @type {import(\"express\").Response} */ (opaque);\n        return res.writeHead(statusCode, omit(headers, ...HOP_BY_HOP_HEADERS));\n      },\n      function (err, { opaque, trailers }) {\n        if (err) return next(assign(err, { statusCode: 502 }));\n        const res = /** @type {import(\"express\").Response} */ (opaque);\n        res.addTrailers(trailers);\n      }\n    );\n  }\n\n  /** @type {express.Application[\"listen\"]} */\n  function listen(\n    /** @type {Parameters<express.Application[\"listen\"]>} */ ...args\n  ) {\n    return express()\n      .use(listener)\n      .listen(...args);\n  }\n\n  return assign(listener, { listen });\n}\n\nmodule.exports = proxy;\n"]}