@@ -421,7 +421,6 @@ class ConfigurableProxy extends EventEmitter {
421
421
// custom error server gets `/CODE?url=/escapedUrl/`, e.g.
422
422
// /404?url=%2Fuser%2Ffoo
423
423
424
- var proxy = this ;
425
424
var errMsg = "" ;
426
425
this . statsd . increment ( "requests." + code , 1 ) ;
427
426
if ( e ) {
@@ -439,16 +438,31 @@ class ConfigurableProxy extends EventEmitter {
439
438
}
440
439
this . log . error ( "%s %s %s %s" , code , req . method , req . url , errMsg ) ;
441
440
if ( ! res ) {
441
+ this . log . debug ( "Socket error, no response to send" ) ;
442
442
// socket-level error, no response to build
443
443
return ;
444
444
}
445
445
if ( this . errorTarget ) {
446
446
var urlSpec = URL . parse ( this . errorTarget ) ;
447
+ // error request is $errorTarget/$code?url=$requestUrl
447
448
urlSpec . search = "?" + querystring . encode ( { url : req . url } ) ;
448
449
urlSpec . pathname = urlSpec . pathname + code . toString ( ) ;
449
450
var secure = / h t t p s / gi. test ( urlSpec . protocol ) ? true : false ;
450
451
var url = URL . format ( urlSpec ) ;
451
- var errorRequest = ( secure ? https : http ) . request ( url , function ( upstream ) {
452
+ this . log . debug ( "Requesting custom error page: %s" , urlSpec . format ( ) ) ;
453
+
454
+ // construct request target from urlSpec
455
+ var target = URL . parse ( url ) ;
456
+ target . method = "GET" ;
457
+
458
+ // add client SSL config if error target is using https
459
+ if ( secure && this . options . clientSsl ) {
460
+ target . key = this . options . clientSsl . key ;
461
+ target . cert = this . options . clientSsl . cert ;
462
+ target . ca = this . options . clientSsl . ca ;
463
+ }
464
+
465
+ var errorRequest = ( secure ? https : http ) . request ( target , function ( upstream ) {
452
466
[ "content-type" , "content-encoding" ] . map ( function ( key ) {
453
467
if ( ! upstream . headers [ key ] ) return ;
454
468
if ( res . setHeader ) res . setHeader ( key , upstream . headers [ key ] ) ;
0 commit comments