Skip to content

Commit 3778727

Browse files
committed
https support for proxy relay
Fix for issue #563
1 parent 84ef1c8 commit 3778727

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/chain.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import http from 'http';
2+
import https from 'https';
23
import dns from 'dns';
34
import { URL } from 'url';
45
import { EventEmitter } from 'events';
@@ -80,7 +81,8 @@ export const chain = (
8081
options.headers.push('proxy-authorization', getBasicAuthorizationHeader(proxy));
8182
}
8283

83-
const client = http.request(proxy.origin, options as unknown as http.ClientRequestArgs);
84+
const fn = proxy.protocol === 'https:' ? https.request : http.request;
85+
const client = fn(proxy.origin, options as unknown as http.ClientRequestArgs);
8486

8587
client.on('connect', (response, targetSocket, clientHead) => {
8688
countTargetBytes(sourceSocket, targetSocket);

src/server.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@ export class Server extends EventEmitter {
453453
throw new Error(`Invalid "upstreamProxyUrl" provided: ${error} (was "${funcResult.upstreamProxyUrl}"`);
454454
}
455455

456-
if (!['http:', ...SOCKS_PROTOCOLS].includes(handlerOpts.upstreamProxyUrlParsed.protocol)) {
456+
if (!['http:', 'https:', ...SOCKS_PROTOCOLS].includes(handlerOpts.upstreamProxyUrlParsed.protocol)) {
457457
// eslint-disable-next-line max-len
458-
throw new Error(`Invalid "upstreamProxyUrl" provided: URL must have one of the following protocols: "http", ${SOCKS_PROTOCOLS.map((p) => `"${p.replace(':', '')}"`).join(', ')} (was "${funcResult.upstreamProxyUrl}")`);
458+
throw new Error(`Invalid "upstreamProxyUrl" provided: URL must have one of the following protocols: "http", "https", ${SOCKS_PROTOCOLS.map((p) => `"${p.replace(':', '')}"`).join(', ')} (was "${funcResult.upstreamProxyUrl}")`);
459459
}
460460
}
461461

0 commit comments

Comments
 (0)