mirror of
https://github.com/nodejs/node.git
synced 2025-12-28 07:50:41 +00:00
This adds an API to dynamically enable built-in proxy support for all of fetch() and http.request()/https.request(), so that users do not have to be aware of them all and configure them one by one. PR-URL: https://github.com/nodejs/node/pull/60953 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Tim Perry <pimterry@gmail.com>
30 lines
745 B
JavaScript
30 lines
745 B
JavaScript
// Tests that http.setGlobalProxyFromEnv() works with http.request().
|
|
|
|
import '../common/index.mjs';
|
|
import assert from 'node:assert';
|
|
import { startTestServers, checkProxiedRequest } from '../common/proxy-server.js';
|
|
const { proxyLogs, shutdown, proxyUrl, httpEndpoint: { requestUrl, serverHost } } = await startTestServers({
|
|
httpEndpoint: true,
|
|
});
|
|
|
|
await checkProxiedRequest({
|
|
REQUEST_URL: requestUrl,
|
|
SET_GLOBAL_PROXY: JSON.stringify({ http_proxy: proxyUrl }),
|
|
}, {
|
|
stdout: 'Hello world',
|
|
});
|
|
|
|
shutdown();
|
|
|
|
const expectedLogs = [{
|
|
method: 'GET',
|
|
url: requestUrl,
|
|
headers: {
|
|
'connection': 'keep-alive',
|
|
'proxy-connection': 'keep-alive',
|
|
'host': serverHost,
|
|
},
|
|
}];
|
|
|
|
assert.deepStrictEqual(proxyLogs, expectedLogs);
|