@@ -421,7 +421,7 @@ 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 ;
424
+ var that = this ;
425
425
var errMsg = "" ;
426
426
this . statsd . increment ( "requests." + code , 1 ) ;
427
427
if ( e ) {
@@ -439,34 +439,27 @@ class ConfigurableProxy extends EventEmitter {
439
439
}
440
440
this . log . error ( "%s %s %s %s" , code , req . method , req . url , errMsg ) ;
441
441
if ( ! res ) {
442
+ this . log . debug ( "socket error, no response to send" ) ;
442
443
// socket-level error, no response to build
443
444
return ;
444
445
}
445
446
if ( this . errorTarget ) {
446
- var urlSpec = URL . parse ( this . errorTarget ) ;
447
- urlSpec . search = "?" + querystring . encode ( { url : req . url } ) ;
448
- urlSpec . pathname = urlSpec . pathname + code . toString ( ) ;
449
- var secure = / h t t p s / gi. test ( urlSpec . protocol ) ? true : false ;
450
- var url = URL . format ( urlSpec ) ;
451
- var errorRequest = ( secure ? https : http ) . request ( url , function ( upstream ) {
452
- [ "content-type" , "content-encoding" ] . map ( function ( key ) {
453
- if ( ! upstream . headers [ key ] ) return ;
454
- if ( res . setHeader ) res . setHeader ( key , upstream . headers [ key ] ) ;
455
- } ) ;
456
- if ( res . writeHead ) res . writeHead ( code ) ;
457
- upstream . on ( "data" , data => {
458
- if ( res . write ) res . write ( data ) ;
459
- } ) ;
460
- upstream . on ( "end" , ( ) => {
461
- if ( res . end ) res . end ( ) ;
462
- } ) ;
463
- } ) ;
464
- errorRequest . on ( "error" , e => {
447
+ var target = URL . parse ( this . errorTarget ) ;
448
+ target . search = "?" + querystring . encode ( { url : req . url } ) ;
449
+ target . pathname = target . pathname + code . toString ( ) ;
450
+
451
+ if ( this . options . clientSsl ) {
452
+ target . key = this . options . clientSsl . key ;
453
+ target . cert = this . options . clientSsl . cert ;
454
+ target . ca = this . options . clientSsl . ca ;
455
+ }
456
+
457
+ this . log . debug ( "sending to custom error page: %s" , target . format ( ) ) ;
458
+ this . proxy . web ( req , res , { target : target } , err => {
465
459
// custom error failed, fallback on default
466
- this . log . error ( "Failed to get custom error page: %s" , e ) ;
467
- this . _handleProxyErrorDefault ( code , kind , req , res ) ;
460
+ that . log . error ( "Failed to get custom error page: %s" , err ) ;
461
+ that . _handleProxyErrorDefault ( code , kind , req , res ) ;
468
462
} ) ;
469
- errorRequest . end ( ) ;
470
463
} else if ( this . errorPath ) {
471
464
var filename = path . join ( this . errorPath , code . toString ( ) + ".html" ) ;
472
465
if ( ! fs . existsSync ( filename ) ) {
0 commit comments