@@ -28,11 +28,11 @@ if (NODE_VER[0] < 9 && (NODE_VER[0] !== 8 || NODE_VER[1] > 4)) {
28
28
}
29
29
30
30
module . exports = {
31
- ws ( req , socket , head , options , onProxyError ) {
32
- impl ( req , socket , head , options , onProxyError )
31
+ ws ( req , socket , head , options , callback ) {
32
+ impl ( req , socket , head , options , callback )
33
33
} ,
34
- web ( req , res , options , onProxyError ) {
35
- impl ( req , res , null , options , onProxyError )
34
+ web ( req , res , options , callback ) {
35
+ impl ( req , res , null , options , callback )
36
36
}
37
37
}
38
38
@@ -44,7 +44,7 @@ function impl (req, resOrSocket, headOrNil, {
44
44
proxyName,
45
45
onReq,
46
46
onRes
47
- } , onProxyError ) {
47
+ } , callback ) {
48
48
let hasError = false
49
49
50
50
function onError ( err , statusCode = err . statusCode || 500 ) {
@@ -64,8 +64,8 @@ function impl (req, resOrSocket, headOrNil, {
64
64
resOrSocket . end ( )
65
65
}
66
66
67
- if ( onProxyError ) {
68
- onProxyError ( err , req , resOrSocket )
67
+ if ( callback ) {
68
+ callback ( err , req , resOrSocket )
69
69
} else {
70
70
throw err
71
71
}
@@ -151,7 +151,7 @@ function proxy (req, resOrSocket, options, onRes, onError) {
151
151
}
152
152
}
153
153
154
- const callback = err => {
154
+ const onProxyError = err => {
155
155
if ( hasError ) {
156
156
return
157
157
}
@@ -168,26 +168,26 @@ function proxy (req, resOrSocket, options, onRes, onError) {
168
168
. on ( 'error' , err => {
169
169
if ( err . code === 'ECONNREFUSED' || err . code === 'ENOTFOUND' ) {
170
170
err . statusCode = 503
171
- callback ( err )
171
+ onProxyError ( err )
172
172
} else if ( / H P E _ I N V A L I D / . test ( err . code ) ) {
173
173
err . statusCode = 502
174
- callback ( err )
174
+ onProxyError ( err )
175
175
} else if ( err . code === 'ECONNRESET' ) {
176
176
if ( ! proxyReq . aborted ) {
177
177
err . statusCode = 502
178
- callback ( err )
178
+ onProxyError ( err )
179
179
}
180
180
} else {
181
- callback ( err )
181
+ onProxyError ( err )
182
182
}
183
183
} )
184
184
// NOTE http.ClientRequest emits "socket hang up" error when aborted
185
185
// before having received a response, i.e. there is no need to listen for
186
186
// proxyReq.on('aborted', ...).
187
- . on ( 'timeout' , ( ) => callback ( createError ( 'gateway timeout' , null , 504 ) ) )
187
+ . on ( 'timeout' , ( ) => onProxyError ( createError ( 'gateway timeout' , null , 504 ) ) )
188
188
. on ( 'response' , proxyRes => {
189
189
try {
190
- proxyRes . on ( 'aborted' , ( ) => callback ( createError ( 'socket hang up' , 'ECONNRESET' , 502 ) ) )
190
+ proxyRes . on ( 'aborted' , ( ) => onProxyError ( createError ( 'socket hang up' , 'ECONNRESET' , 502 ) ) )
191
191
192
192
if ( resOrSocket instanceof net . Socket ) {
193
193
if ( onRes ) {
@@ -214,11 +214,11 @@ function proxy (req, resOrSocket, options, onRes, onError) {
214
214
resOrSocket . addTrailers ( proxyRes . trailers )
215
215
} )
216
216
proxyRes
217
- . on ( 'error' , callback )
217
+ . on ( 'error' , onProxyError )
218
218
. pipe ( resOrSocket )
219
219
}
220
220
} catch ( err ) {
221
- callback ( err )
221
+ onProxyError ( err )
222
222
}
223
223
} )
224
224
@@ -251,14 +251,14 @@ function proxy (req, resOrSocket, options, onRes, onError) {
251
251
. join ( '\r\n' ) + '\r\n\r\n'
252
252
)
253
253
254
- proxyRes . on ( 'error' , callback )
254
+ proxyRes . on ( 'error' , onProxyError )
255
255
256
256
proxySocket
257
- . on ( 'error' , callback )
257
+ . on ( 'error' , onProxyError )
258
258
. pipe ( resOrSocket )
259
259
. pipe ( proxySocket )
260
260
} catch ( err ) {
261
- callback ( err )
261
+ onProxyError ( err )
262
262
}
263
263
} )
264
264
}
0 commit comments