Skip to content

Commit

Permalink
fix: add Host header when used with http_proxy (#10080)
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Rudenko <alexrudenko@chromium.org>
  • Loading branch information
magicdawn and OrKoN committed Apr 27, 2023
1 parent e02a3cf commit edbfff7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/browsers/src/httpUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions packages/browsers/test/src/chrome/install.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(
Expand All @@ -164,6 +166,7 @@ describe('Chrome install', () => {
);
originalRequest.pipe(proxyRequest, {end: true});
proxiedRequestUrls.push(url);
proxiedRequestHosts.push(originalRequest.headers?.host || '');
}
)
.listen({
Expand Down Expand Up @@ -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 () {
Expand All @@ -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://', ''),
]);
});
});
});

0 comments on commit edbfff7

Please sign in to comment.