@@ -9,6 +9,7 @@ const util = require('util');
9
9
const { expect, assert } = require ( 'chai' ) ;
10
10
const proxy = require ( 'proxy' ) ;
11
11
const http = require ( 'http' ) ;
12
+ const https = require ( 'https' ) ;
12
13
const portastic = require ( 'portastic' ) ;
13
14
const request = require ( 'request' ) ;
14
15
const WebSocket = require ( 'faye-websocket' ) ;
@@ -1337,6 +1338,45 @@ it('supports localAddress', async () => {
1337
1338
}
1338
1339
} ) ;
1339
1340
1341
+ it ( 'supports https proxy relay' , async ( ) => {
1342
+ const target = https . createServer ( ( ) => {
1343
+ } ) ;
1344
+ target . listen ( ( ) => {
1345
+ } ) ;
1346
+
1347
+ const proxyServer = new ProxyChain . Server ( {
1348
+ port : 6666 ,
1349
+ prepareRequestFunction : ( ) => {
1350
+ console . log ( `https://localhost:${ target . address ( ) . port } ` ) ;
1351
+ return {
1352
+ upstreamProxyUrl : `https://localhost:${ target . address ( ) . port } ` ,
1353
+ } ;
1354
+ } ,
1355
+ } ) ;
1356
+ let proxyServerError = false ;
1357
+ proxyServer . on ( 'requestFailed' , ( ) => {
1358
+ // requestFailed will be called if we pass an invalid proxy url
1359
+ proxyServerError = true ;
1360
+ } ) ;
1361
+
1362
+ await proxyServer . listen ( ) ;
1363
+
1364
+ try {
1365
+ await requestPromised ( {
1366
+ url : 'https://www.google.com' ,
1367
+ proxy : 'http://localhost:6666' ,
1368
+ strictSSL : false ,
1369
+ } ) ;
1370
+ } catch ( e ) {
1371
+ // the request will fail with the following error:
1372
+ // Error: tunneling socket could not be established, statusCode=599
1373
+ }
1374
+ expect ( proxyServerError ) . to . be . equal ( false ) ;
1375
+
1376
+ proxyServer . close ( ) ;
1377
+ target . close ( ) ;
1378
+ } ) ;
1379
+
1340
1380
it ( 'supports custom CONNECT server handler' , async ( ) => {
1341
1381
const server = new Server ( {
1342
1382
port : 0 ,
0 commit comments