@@ -45,12 +45,12 @@ function impl (req, resOrSocket, headOrNil, {
45
45
onReq,
46
46
onRes
47
47
} , callback ) {
48
- const onError = ErrorHandler . create ( req , resOrSocket , callback )
48
+ const errorHandler = ErrorHandler . create ( req , resOrSocket , callback )
49
49
50
- resOrSocket . on ( 'error' , onError )
50
+ resOrSocket . on ( 'error' , errorHandler )
51
51
52
52
const incoming = req . stream || req
53
- incoming . on ( 'error' , onError )
53
+ incoming . on ( 'error' , errorHandler )
54
54
55
55
try {
56
56
if ( resOrSocket instanceof net . Socket ) {
@@ -77,7 +77,7 @@ function impl (req, resOrSocket, headOrNil, {
77
77
}
78
78
79
79
if ( timeout ) {
80
- req . setTimeout ( timeout , onError . requestTimeout )
80
+ req . setTimeout ( timeout , errorHandler . requestTimeout )
81
81
}
82
82
83
83
if ( resOrSocket instanceof net . Socket ) {
@@ -111,28 +111,27 @@ function impl (req, resOrSocket, headOrNil, {
111
111
onReq ( req , options )
112
112
}
113
113
114
- return proxy ( req , resOrSocket , options , onRes , onError )
114
+ return proxy ( req , resOrSocket , options , onRes , errorHandler )
115
115
} catch ( err ) {
116
- return onError ( err )
116
+ return errorHandler ( err )
117
117
}
118
118
}
119
119
120
- function proxy ( req , resOrSocket , options , onRes , onError ) {
120
+ function proxy ( req , resOrSocket , options , onRes , errorHandler ) {
121
121
const proxyReq = http . request ( options )
122
-
123
- const onProxyError = ProxyErrorHandler . create ( req , proxyReq , onError )
122
+ const proxyErrorHandler = ProxyErrorHandler . create ( req , proxyReq , errorHandler )
124
123
125
124
req
126
125
. pipe ( proxyReq )
127
- . on ( 'error' , onProxyError )
126
+ . on ( 'error' , proxyErrorHandler )
128
127
// NOTE http.ClientRequest emits "socket hang up" error when aborted
129
128
// before having received a response, i.e. there is no need to listen for
130
129
// proxyReq.on('aborted', ...).
131
- . on ( 'timeout' , onProxyError . gatewayTimeout )
132
- . on ( 'response' , ProxyResponseHandler . create ( req , resOrSocket , onRes , onProxyError ) )
130
+ . on ( 'timeout' , proxyErrorHandler . gatewayTimeout )
131
+ . on ( 'response' , ProxyResponseHandler . create ( req , resOrSocket , onRes , proxyErrorHandler ) )
133
132
134
133
if ( resOrSocket instanceof net . Socket ) {
135
- proxyReq . on ( 'upgrade' , ProxyUpgradeHandler . create ( req , resOrSocket , onProxyError ) )
134
+ proxyReq . on ( 'upgrade' , ProxyUpgradeHandler . create ( req , resOrSocket , proxyErrorHandler ) )
136
135
}
137
136
}
138
137
@@ -277,7 +276,7 @@ class ProxyErrorHandler {
277
276
this . hasError = null
278
277
this . req = null
279
278
this . proxyReq = null
280
- this . onError = null
279
+ this . errorHandler = null
281
280
282
281
this . _release = this . _release . bind ( this )
283
282
this . _handle = this . _handle . bind ( this )
@@ -305,7 +304,7 @@ class ProxyErrorHandler {
305
304
}
306
305
307
306
this . _abort ( )
308
- this . onError ( err )
307
+ this . errorHandler ( err )
309
308
}
310
309
311
310
_gatewayTimeout ( ) {
@@ -328,15 +327,15 @@ class ProxyErrorHandler {
328
327
this . hasError = null
329
328
this . req = null
330
329
this . proxyReq = null
331
- this . onError = null
330
+ this . errorHandler = null
332
331
ProxyErrorHandler . pool . push ( this )
333
332
}
334
333
335
- static create ( req , proxyReq , onError ) {
334
+ static create ( req , proxyReq , errorHandler ) {
336
335
const handler = ProxyErrorHandler . pool . pop ( ) || new ProxyErrorHandler ( )
337
336
handler . req = req
338
337
handler . proxyReq = proxyReq
339
- handler . onError = onError
338
+ handler . errorHandler = errorHandler
340
339
handler . req . on ( 'close' , handler . _release )
341
340
return handler . _handle
342
341
}
@@ -352,7 +351,7 @@ class ProxyResponseHandler {
352
351
this . req = null
353
352
this . resOrSocket = null
354
353
this . onRes = null
355
- this . onProxyError = null
354
+ this . proxyErrorHandler = null
356
355
this . proxyRes = null
357
356
358
357
this . _handle = this . _handle . bind ( this )
@@ -368,7 +367,7 @@ class ProxyResponseHandler {
368
367
this . proxyRes = proxyRes
369
368
370
369
try {
371
- proxyRes . on ( 'aborted' , this . onProxyError . socketHangup )
370
+ proxyRes . on ( 'aborted' , this . proxyErrorHandler . socketHangup )
372
371
373
372
if ( this . resOrSocket instanceof net . Socket ) {
374
373
if ( this . onRes ) {
@@ -393,29 +392,29 @@ class ProxyResponseHandler {
393
392
this . resOrSocket . writeHead ( this . resOrSocket . statusCode )
394
393
proxyRes . on ( 'end' , this . _addTrailers )
395
394
proxyRes
396
- . on ( 'error' , this . onProxyError )
395
+ . on ( 'error' , this . proxyErrorHandler )
397
396
. pipe ( this . resOrSocket )
398
397
}
399
398
} catch ( err ) {
400
- this . onProxyError ( err )
399
+ this . proxyErrorHandler ( err )
401
400
}
402
401
}
403
402
404
403
_release ( ) {
405
404
this . req = null
406
405
this . resOrSocket = null
407
406
this . onRes = null
408
- this . onProxyError = null
407
+ this . proxyErrorHandler = null
409
408
this . proxyRes = null
410
409
ProxyResponseHandler . pool . push ( this )
411
410
}
412
411
413
- static create ( req , resOrSocket , onRes , onProxyError ) {
412
+ static create ( req , resOrSocket , onRes , proxyErrorHandler ) {
414
413
const handler = ProxyResponseHandler . pool . pop ( ) || new ProxyResponseHandler ( )
415
414
handler . req = req
416
415
handler . resOrSocket = resOrSocket
417
416
handler . onRes = onRes
418
- handler . onProxyError = onProxyError
417
+ handler . proxyErrorHandler = proxyErrorHandler
419
418
handler . proxyRes = null
420
419
handler . req . on ( 'close' , handler . _release )
421
420
return handler . _handle
@@ -427,7 +426,7 @@ class ProxyUpgradeHandler {
427
426
constructor ( ) {
428
427
this . req = null
429
428
this . resOrSocket = null
430
- this . onProxyError = null
429
+ this . proxyErrorHandler = null
431
430
this . proxyRes = null
432
431
this . proxySocket = null
433
432
@@ -464,14 +463,14 @@ class ProxyUpgradeHandler {
464
463
465
464
this . resOrSocket . write ( head )
466
465
467
- proxyRes . on ( 'error' , this . onProxyError )
466
+ proxyRes . on ( 'error' , this . proxyErrorHandler )
468
467
469
468
proxySocket
470
- . on ( 'error' , this . onProxyError )
469
+ . on ( 'error' , this . proxyErrorHandler )
471
470
. pipe ( this . resOrSocket )
472
471
. pipe ( proxySocket )
473
472
} catch ( err ) {
474
- this . onProxyError ( err )
473
+ this . proxyErrorHandler ( err )
475
474
}
476
475
}
477
476
@@ -481,17 +480,17 @@ class ProxyUpgradeHandler {
481
480
482
481
this . req = null
483
482
this . resOrSocket = null
484
- this . onProxyError = null
483
+ this . proxyErrorHandler = null
485
484
this . proxyRes = null
486
485
this . proxySocket = null
487
486
ProxyUpgradeHandler . pool . push ( this )
488
487
}
489
488
490
- static create ( req , resOrSocket , onProxyError ) {
489
+ static create ( req , resOrSocket , proxyErrorHandler ) {
491
490
const handler = ProxyUpgradeHandler . pool . pop ( ) || new ProxyUpgradeHandler ( )
492
491
handler . req = req
493
492
handler . resOrSocket = resOrSocket
494
- handler . onProxyError = onProxyError
493
+ handler . proxyErrorHandler = proxyErrorHandler
495
494
handler . req . on ( 'close' , handler . _release )
496
495
return handler . _handle
497
496
}
0 commit comments