You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add HTTPS upstream proxy support with option to ignore proxy cert errors (#577)
This PR adds support for a new boolean option `ignoreProxyCertificate`. If set to `true`, certificate errors will be ignored, which can be useful for HTTPS proxies with self-signed certificates.
Usage:
```
const server = new Server({
prepareRequestFunction: () => ({
upstreamProxyUrl: 'https://user:pass@myproxy:8080',
ignoreUpstreamProxyCertificate: true // Useful for self-signed cert
})
}).listen();
```
Anonymize:
```
anonymizeProxy({
url: 'https://user:pass@myproxy:8080',
ignoreProxyCertificate: true,
}).then((anonymizedURL) => {
console.log(`Anonymized URL: ${anonymizedURL}`);
});
```
Create tunnel:
```
createTunnel(
'https://user:pass@myproxy:8080',
targetHost,
{ ignoreProxyCertificate: true }
).then((url) => {
console.log('Tunnel endpoint:', url);
});
```
// Applies to HTTPS upstream proxy. If set to true, requests made to the proxy will
80
+
// ignore certificate errors. Useful when upstream proxy uses self-signed certificate. By default "false".
81
+
ignoreUpstreamProxyCertificate:true
82
+
79
83
// If "requestAuthentication" is true, you can use the following property
80
84
// to define a custom error message to return to the client instead of the default "Proxy credentials required"
81
85
failMsg:'Bad username or password, please try again.',
@@ -368,10 +372,13 @@ The package also provides several utility functions.
368
372
369
373
### `anonymizeProxy({ url, port }, callback)`
370
374
371
-
Parses and validates a HTTP proxy URL. If the proxy requires authentication,
375
+
Parses and validates a HTTP/HTTPS proxy URL. If the proxy requires authentication,
372
376
then the function starts an open local proxy server that forwards to the proxy.
373
377
The port (on which the local proxy server will start) can be set via the `port` property of the first argument, if not provided, it will be chosen randomly.
374
378
379
+
For HTTPS proxy with self-signed certificate, set `ignoreProxyCertificate` property of the first argument to `true` to ignore certificate errors in
380
+
proxy requests.
381
+
375
382
The function takes an optional callback that receives the anonymous proxy URL.
376
383
If no callback is supplied, the function returns a promise that resolves to a String with
377
384
anonymous proxy URL or the original URL if it was already anonymous.
@@ -420,13 +427,14 @@ If callback is not provided, the function returns a promise instead.
Creates a TCP tunnel to `targetHost` that goes through a HTTP proxy server
430
+
Creates a TCP tunnel to `targetHost` that goes through a HTTP/HTTPS proxy server
424
431
specified by the `proxyUrl` parameter.
425
432
426
433
The optional `options` parameter is an object with the following properties:
427
434
-`port: Number` - Enables specifying the local port to listen at. By default `0`,
428
435
which means a random port will be selected.
429
436
-`hostname: String` - Local hostname to listen at. By default `localhost`.
437
+
-`ignoreProxyCertificate` - For HTTPS proxy, ignore certificate errors in proxy requests. Useful for proxy with self-signed certificate. By default `false`.
430
438
-`verbose: Boolean` - If `true`, the functions logs a lot. By default `false`.
431
439
432
440
The result of the function is a local endpoint in a form of `hostname:port`.
thrownewError(`Invalid "proxyUrl" provided: URL must have one of the following protocols: "http", ${SOCKS_PROTOCOLS.map((p)=>`"${p.replace(':','')}"`).join(', ')} (was "${parsedProxyUrl}")`);
thrownewError(`Invalid "proxyUrl" provided: URL must have one of the following protocols: "http", "https", ${SOCKS_PROTOCOLS.map((p)=>`"${p.replace(':','')}"`).join(', ')} (was "${parsedProxyUrl}")`);
44
51
}
45
52
46
-
// If upstream proxy requires no password, return it directly
0 commit comments