From 7358e9e92f73a8485a288893dd7daf228a673ac3 Mon Sep 17 00:00:00 2001 From: Alex Rudenko Date: Thu, 4 May 2023 10:19:56 +0200 Subject: [PATCH] refactor: use http-proxy-agent (#10132) --- package-lock.json | 13 +++++++------ packages/browsers/package.json | 1 + packages/browsers/src/httpUtil.ts | 8 ++------ 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/package-lock.json b/package-lock.json index 56b078e7..a11a7e99 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1572,7 +1572,6 @@ }, "node_modules/@tootallnate/once": { "version": "2.0.0", - "dev": true, "license": "MIT", "engines": { "node": ">= 10" @@ -4564,8 +4563,8 @@ }, "node_modules/http-proxy-agent": { "version": "5.0.0", - "dev": true, - "license": "MIT", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz", + "integrity": "sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==", "dependencies": { "@tootallnate/once": "2", "agent-base": "6", @@ -9320,6 +9319,7 @@ "dependencies": { "debug": "4.3.4", "extract-zip": "2.0.1", + "http-proxy-agent": "5.0.0", "https-proxy-agent": "5.0.1", "progress": "2.0.3", "proxy-from-env": "1.1.0", @@ -10392,6 +10392,7 @@ "@types/yargs": "17.0.22", "debug": "4.3.4", "extract-zip": "2.0.1", + "http-proxy-agent": "5.0.0", "https-proxy-agent": "5.0.1", "progress": "2.0.3", "proxy-from-env": "1.1.0", @@ -10611,8 +10612,7 @@ "dev": true }, "@tootallnate/once": { - "version": "2.0.0", - "dev": true + "version": "2.0.0" }, "@tsconfig/node10": { "version": "1.0.9", @@ -12569,7 +12569,8 @@ }, "http-proxy-agent": { "version": "5.0.0", - "dev": true, + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz", + "integrity": "sha512-n2hY8YdoRE1i7r6M0w9DIw5GgZN0G25P8zLCRQ8rjXtTU3vsNFBI/vWK/UIeE6g5MUUz6avwAPXmL6Fy9D/90w==", "requires": { "@tootallnate/once": "2", "agent-base": "6", diff --git a/packages/browsers/package.json b/packages/browsers/package.json index c28787e1..9c95a372 100644 --- a/packages/browsers/package.json +++ b/packages/browsers/package.json @@ -101,6 +101,7 @@ "dependencies": { "debug": "4.3.4", "extract-zip": "2.0.1", + "http-proxy-agent": "5.0.0", "https-proxy-agent": "5.0.1", "progress": "2.0.3", "proxy-from-env": "1.1.0", diff --git a/packages/browsers/src/httpUtil.ts b/packages/browsers/src/httpUtil.ts index 5b6150f7..69f41239 100644 --- a/packages/browsers/src/httpUtil.ts +++ b/packages/browsers/src/httpUtil.ts @@ -19,6 +19,7 @@ import * as http from 'http'; import * as https from 'https'; import {URL} from 'url'; +import createHttpProxyAgent from 'http-proxy-agent'; import createHttpsProxyAgent from 'https-proxy-agent'; import {getProxyForUrl} from 'proxy-from-env'; @@ -57,12 +58,7 @@ export function httpRequest( if (proxyURL) { const proxy = new URL(proxyURL); if (proxy.protocol === 'http:') { - options.path = url.href; - options.hostname = proxy.hostname; - options.protocol = proxy.protocol; - options.port = proxy.port; - options.headers ??= {}; - options.headers['Host'] ||= url.host; + options.agent = createHttpProxyAgent(proxyURL); } else { options.agent = createHttpsProxyAgent({ host: proxy.host,