fix: add Host header when used with http_proxy (#10080)

Co-authored-by: Alex Rudenko <alexrudenko@chromium.org>
This commit is contained in:
Tao 2023-04-27 19:37:52 +08:00 committed by GitHub
parent e02a3cf6e4
commit edbfff7b04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View File

@ -61,6 +61,8 @@ export function httpRequest(
options.hostname = proxy.hostname;
options.protocol = proxy.protocol;
options.port = proxy.port;
options.headers ??= {};
options.headers['Host'] ||= url.host;
} else {
options.agent = createHttpsProxyAgent({
host: proxy.host,

View File

@ -136,9 +136,11 @@ describe('Chrome install', () => {
const proxyUrl = new URL(`http://localhost:54321`);
let proxyServer: http.Server;
let proxiedRequestUrls: string[] = [];
let proxiedRequestHosts: string[] = [];
beforeEach(() => {
proxiedRequestUrls = [];
proxiedRequestHosts = [];
proxyServer = http
.createServer(
(
@ -164,6 +166,7 @@ describe('Chrome install', () => {
);
originalRequest.pipe(proxyRequest, {end: true});
proxiedRequestUrls.push(url);
proxiedRequestHosts.push(originalRequest.headers?.host || '');
}
)
.listen({
@ -203,6 +206,9 @@ describe('Chrome install', () => {
assert.deepStrictEqual(proxiedRequestUrls, [
getServerUrl() + '/113.0.5672.0/linux64/chrome-linux64.zip',
]);
assert.deepStrictEqual(proxiedRequestHosts, [
getServerUrl().replace('http://', ''),
]);
});
it('can download via a proxy', async function () {
@ -225,6 +231,9 @@ describe('Chrome install', () => {
assert.deepStrictEqual(proxiedRequestUrls, [
getServerUrl() + '/113.0.5672.0/linux64/chrome-linux64.zip',
]);
assert.deepStrictEqual(proxiedRequestHosts, [
getServerUrl().replace('http://', ''),
]);
});
});
});