{"version":3,"file":"node-http-proxy.d.ts","sourceRoot":"","sources":["../../src/utils/node-http-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,WAAW,CAAC;AACpD,OAAO,KAAK,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,YAAY,CAAC;AAatD,MAAM,WAAW,mBAAmB;IACnC,SAAS,EAAE,SAAS,CAAC;IACrB,UAAU,EAAE,UAAU,CAAC;CACvB;AAED,eAAO,MAAM,kCAAkC,4GAC2D,CAAC;AAsE3G,wBAAgB,4BAA4B,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,GAAG,GAAG,GAAG,SAAS,CAoBrF;AAED,wBAAgB,8BAA8B,CAAC,SAAS,EAAE,MAAM,GAAG,GAAG,GAAG,mBAAmB,GAAG,SAAS,CAUvG","sourcesContent":["import type { Agent as HttpAgent } from \"node:http\";\nimport type { Agent as HttpsAgent } from \"node:https\";\nimport { HttpProxyAgent } from \"http-proxy-agent\";\nimport { HttpsProxyAgent } from \"https-proxy-agent\";\n\nconst DEFAULT_PROXY_PORTS: Record<string, number> = {\n\tftp: 21,\n\tgopher: 70,\n\thttp: 80,\n\thttps: 443,\n\tws: 80,\n\twss: 443,\n};\n\nexport interface NodeHttpProxyAgents {\n\thttpAgent: HttpAgent;\n\thttpsAgent: HttpsAgent;\n}\n\nexport const UNSUPPORTED_PROXY_PROTOCOL_MESSAGE =\n\t\"Unsupported proxy protocol. SOCKS and PAC proxy URLs are not supported; use an HTTP or HTTPS proxy URL.\";\n\nfunction getProxyEnv(key: string): string {\n\treturn process.env[key.toLowerCase()] || process.env[key.toUpperCase()] || \"\";\n}\n\nfunction parseProxyTargetUrl(targetUrl: string | URL): URL | undefined {\n\tif (targetUrl instanceof URL) {\n\t\treturn targetUrl;\n\t}\n\n\ttry {\n\t\treturn new URL(targetUrl);\n\t} catch {\n\t\treturn undefined;\n\t}\n}\n\nfunction shouldProxyHostname(hostname: string, port: number): boolean {\n\tconst noProxy = getProxyEnv(\"no_proxy\").toLowerCase();\n\tif (!noProxy) {\n\t\treturn true;\n\t}\n\tif (noProxy === \"*\") {\n\t\treturn false;\n\t}\n\n\treturn noProxy.split(/[,\\s]/).every((proxy) => {\n\t\tif (!proxy) {\n\t\t\treturn true;\n\t\t}\n\n\t\tconst parsedProxy = proxy.match(/^(.+):(\\d+)$/);\n\t\tlet proxyHostname = parsedProxy ? parsedProxy[1] : proxy;\n\t\tconst proxyPort = parsedProxy ? Number.parseInt(parsedProxy[2]!, 10) : 0;\n\t\tif (proxyPort && proxyPort !== port) {\n\t\t\treturn true;\n\t\t}\n\n\t\tif (!/^[.*]/.test(proxyHostname)) {\n\t\t\treturn hostname !== proxyHostname;\n\t\t}\n\n\t\tif (proxyHostname.startsWith(\"*\")) {\n\t\t\tproxyHostname = proxyHostname.slice(1);\n\t\t}\n\t\treturn !hostname.endsWith(proxyHostname);\n\t});\n}\n\nfunction getProxyForUrl(targetUrl: string | URL): string {\n\tconst parsedUrl = parseProxyTargetUrl(targetUrl);\n\tif (!parsedUrl?.protocol || !parsedUrl.host) {\n\t\treturn \"\";\n\t}\n\n\tconst protocol = parsedUrl.protocol.split(\":\", 1)[0]!;\n\tconst hostname = parsedUrl.host.replace(/:\\d*$/, \"\");\n\tconst port = Number.parseInt(parsedUrl.port, 10) || DEFAULT_PROXY_PORTS[protocol] || 0;\n\tif (!shouldProxyHostname(hostname, port)) {\n\t\treturn \"\";\n\t}\n\n\tlet proxy = getProxyEnv(`${protocol}_proxy`) || getProxyEnv(\"all_proxy\");\n\tif (proxy && !proxy.includes(\"://\")) {\n\t\tproxy = `${protocol}://${proxy}`;\n\t}\n\treturn proxy;\n}\n\nexport function resolveHttpProxyUrlForTarget(targetUrl: string | URL): URL | undefined {\n\tconst proxy = getProxyForUrl(targetUrl);\n\tif (!proxy) {\n\t\treturn undefined;\n\t}\n\n\tlet proxyUrl: URL;\n\ttry {\n\t\tproxyUrl = new URL(proxy);\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Invalid proxy URL ${JSON.stringify(proxy)}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n\n\tif (proxyUrl.protocol !== \"http:\" && proxyUrl.protocol !== \"https:\") {\n\t\tthrow new Error(`${UNSUPPORTED_PROXY_PROTOCOL_MESSAGE} Got ${proxyUrl.protocol}`);\n\t}\n\n\treturn proxyUrl;\n}\n\nexport function createHttpProxyAgentsForTarget(targetUrl: string | URL): NodeHttpProxyAgents | undefined {\n\tconst proxyUrl = resolveHttpProxyUrlForTarget(targetUrl);\n\tif (!proxyUrl) {\n\t\treturn undefined;\n\t}\n\n\treturn {\n\t\thttpAgent: new HttpProxyAgent(proxyUrl),\n\t\thttpsAgent: new HttpsProxyAgent(proxyUrl) as unknown as HttpsAgent,\n\t};\n}\n"]}