fix: add Host header when used with http_proxy (#10080)
Co-authored-by: Alex Rudenko <alexrudenko@chromium.org>
This commit is contained in:
parent
e02a3cf6e4
commit
edbfff7b04
@ -61,6 +61,8 @@ export function httpRequest(
|
|||||||
options.hostname = proxy.hostname;
|
options.hostname = proxy.hostname;
|
||||||
options.protocol = proxy.protocol;
|
options.protocol = proxy.protocol;
|
||||||
options.port = proxy.port;
|
options.port = proxy.port;
|
||||||
|
options.headers ??= {};
|
||||||
|
options.headers['Host'] ||= url.host;
|
||||||
} else {
|
} else {
|
||||||
options.agent = createHttpsProxyAgent({
|
options.agent = createHttpsProxyAgent({
|
||||||
host: proxy.host,
|
host: proxy.host,
|
||||||
|
@ -136,9 +136,11 @@ describe('Chrome install', () => {
|
|||||||
const proxyUrl = new URL(`http://localhost:54321`);
|
const proxyUrl = new URL(`http://localhost:54321`);
|
||||||
let proxyServer: http.Server;
|
let proxyServer: http.Server;
|
||||||
let proxiedRequestUrls: string[] = [];
|
let proxiedRequestUrls: string[] = [];
|
||||||
|
let proxiedRequestHosts: string[] = [];
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
proxiedRequestUrls = [];
|
proxiedRequestUrls = [];
|
||||||
|
proxiedRequestHosts = [];
|
||||||
proxyServer = http
|
proxyServer = http
|
||||||
.createServer(
|
.createServer(
|
||||||
(
|
(
|
||||||
@ -164,6 +166,7 @@ describe('Chrome install', () => {
|
|||||||
);
|
);
|
||||||
originalRequest.pipe(proxyRequest, {end: true});
|
originalRequest.pipe(proxyRequest, {end: true});
|
||||||
proxiedRequestUrls.push(url);
|
proxiedRequestUrls.push(url);
|
||||||
|
proxiedRequestHosts.push(originalRequest.headers?.host || '');
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.listen({
|
.listen({
|
||||||
@ -203,6 +206,9 @@ describe('Chrome install', () => {
|
|||||||
assert.deepStrictEqual(proxiedRequestUrls, [
|
assert.deepStrictEqual(proxiedRequestUrls, [
|
||||||
getServerUrl() + '/113.0.5672.0/linux64/chrome-linux64.zip',
|
getServerUrl() + '/113.0.5672.0/linux64/chrome-linux64.zip',
|
||||||
]);
|
]);
|
||||||
|
assert.deepStrictEqual(proxiedRequestHosts, [
|
||||||
|
getServerUrl().replace('http://', ''),
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can download via a proxy', async function () {
|
it('can download via a proxy', async function () {
|
||||||
@ -225,6 +231,9 @@ describe('Chrome install', () => {
|
|||||||
assert.deepStrictEqual(proxiedRequestUrls, [
|
assert.deepStrictEqual(proxiedRequestUrls, [
|
||||||
getServerUrl() + '/113.0.5672.0/linux64/chrome-linux64.zip',
|
getServerUrl() + '/113.0.5672.0/linux64/chrome-linux64.zip',
|
||||||
]);
|
]);
|
||||||
|
assert.deepStrictEqual(proxiedRequestHosts, [
|
||||||
|
getServerUrl().replace('http://', ''),
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user