mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
http,https: handle IPv6 with proxies
This simplifies the proxy configuration handling code, adds tests to make sure the proxy support works with IPv6 and throws correct errors for invalid proxy IPs. Drive-by: remove useless properties from ProxyConfig PR-URL: https://github.com/nodejs/node/pull/59894 Refs: https://github.com/nodejs/node/issues/57872 Reviewed-By: Aditi Singh <aditisingh1400@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
This commit is contained in:
1 parent
b970c0bbc2
commit
6695067636
6 files changed
+208
-21
No files matched your search
+7
-3
@@ -68,7 +68,7 @@ let debug = require('internal/util/debuglog').debuglog('https', (fn) => {
|
||||
const net = require('net');
|
||||
const { URL, urlToHttpOptions, isURL } = require('internal/url');
|
||||
const { validateObject } = require('internal/validators');
|
||||
const { isIP, isIPv6 } = require('internal/net');
|
||||
const { isIP } = require('internal/net');
|
||||
const assert = require('internal/assert');
|
||||
const { getOptionValue } = require('internal/options');
|
||||
|
||||
@@ -171,7 +171,11 @@ function getTunnelConfigForProxiedHttps(agent, reqOptions) {
|
||||
}
|
||||
const { auth, href } = agent[kProxyConfig];
|
||||
// The request is a HTTPS request, assemble the payload for establishing the tunnel.
|
||||
const requestHost = isIPv6(reqOptions.host) ? `[${reqOptions.host}]` : reqOptions.host;
|
||||
const ipType = isIP(reqOptions.host);
|
||||
// The request target must put IPv6 address in square brackets.
|
||||
// Here reqOptions is already processed by urlToHttpOptions so we'll add them back if necessary.
|
||||
// See https://www.rfc-editor.org/rfc/rfc3986#section-3.2.2
|
||||
const requestHost = ipType === 6 ? `[${reqOptions.host}]` : reqOptions.host;
|
||||
const requestPort = reqOptions.port || agent.defaultPort;
|
||||
const endpoint = `${requestHost}:${requestPort}`;
|
||||
// The ClientRequest constructor should already have validated the host and the port.
|
||||
@@ -198,7 +202,7 @@ function getTunnelConfigForProxiedHttps(agent, reqOptions) {
|
||||
proxyTunnelPayload: payload,
|
||||
requestOptions: { // Options used for the request sent after the tunnel is established.
|
||||
__proto__: null,
|
||||
servername: reqOptions.servername || (isIP(reqOptions.host) ? undefined : reqOptions.host),
|
||||
servername: reqOptions.servername || ipType ? undefined : reqOptions.host,
|
||||
...reqOptions,
|
||||
},
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user