@@ -213,6 +213,67 @@ describe("follow-redirects", function () {
213
213
} ) ;
214
214
} ) ;
215
215
216
+ it ( "http.get to bracketed IPv4 address" , function ( ) {
217
+ var error = null ;
218
+ try {
219
+ http . get ( "http://[127.0.0.1]:3600/a" ) ;
220
+ }
221
+ catch ( err ) {
222
+ error = err ;
223
+ }
224
+ assert ( error instanceof Error ) ;
225
+ assert ( error instanceof TypeError ) ;
226
+ assert . equal ( error . code , "ERR_INVALID_URL" ) ;
227
+ assert . equal ( error . input , "http://[127.0.0.1]:3600/a" ) ;
228
+ } ) ;
229
+
230
+ it ( "http.get to bracketed IPv4 address specified as host" , function ( ) {
231
+ var error = null ;
232
+ try {
233
+ http . get ( {
234
+ host : "[127.0.0.1]:3600" ,
235
+ path : "/a" ,
236
+ } ) ;
237
+ }
238
+ catch ( err ) {
239
+ error = err ;
240
+ }
241
+ assert ( error instanceof Error ) ;
242
+ assert ( error instanceof TypeError ) ;
243
+ assert . equal ( error . code , "ERR_INVALID_URL" ) ;
244
+ } ) ;
245
+
246
+ it ( "http.get to bracketed IPv4 address specified as hostname" , function ( ) {
247
+ var error = null ;
248
+ try {
249
+ http . get ( {
250
+ hostname : "[127.0.0.1]" ,
251
+ port : 3600 ,
252
+ path : "/a" ,
253
+ } ) ;
254
+ }
255
+ catch ( err ) {
256
+ error = err ;
257
+ }
258
+ assert ( error instanceof Error ) ;
259
+ assert ( error instanceof TypeError ) ;
260
+ assert . equal ( error . code , "ERR_INVALID_URL" ) ;
261
+ } ) ;
262
+
263
+ it ( "http.get to bracketed hostname" , function ( ) {
264
+ var error = null ;
265
+ try {
266
+ http . get ( "http://[localhost]:3600/a" ) ;
267
+ }
268
+ catch ( err ) {
269
+ error = err ;
270
+ }
271
+ assert ( error instanceof Error ) ;
272
+ assert ( error instanceof TypeError ) ;
273
+ assert . equal ( error . code , "ERR_INVALID_URL" ) ;
274
+ assert . equal ( error . input , "http://[localhost]:3600/a" ) ;
275
+ } ) ;
276
+
216
277
it ( "http.get redirecting to IPv4 address" , function ( ) {
217
278
app . get ( "/a" , redirectsTo ( "http://127.0.0.1:3600/b" ) ) ;
218
279
app . get ( "/b" , sendsJson ( { a : "b" } ) ) ;
@@ -241,6 +302,46 @@ describe("follow-redirects", function () {
241
302
} ) ;
242
303
} ) ;
243
304
305
+ it ( "http.get redirecting to bracketed IPv4 address" , function ( ) {
306
+ app . get ( "/a" , redirectsTo ( "http://[127.0.0.1]:3600/b" ) ) ;
307
+ app . get ( "/b" , sendsJson ( { a : "b" } ) ) ;
308
+
309
+ return server . start ( app )
310
+ . then ( asPromise ( function ( resolve , reject ) {
311
+ http . get ( "http://localhost:3600/a" , concatJson ( reject ) ) . on ( "error" , resolve ) ;
312
+ } ) )
313
+ . then ( function ( error ) {
314
+ assert ( error instanceof Error ) ;
315
+ assert . equal ( error . code , "ERR_FR_REDIRECTION_FAILURE" ) ;
316
+
317
+ var cause = error . cause ;
318
+ assert ( cause instanceof Error ) ;
319
+ assert ( cause instanceof TypeError ) ;
320
+ assert . equal ( cause . code , "ERR_INVALID_URL" ) ;
321
+ assert . equal ( cause . input , "http://[127.0.0.1]:3600/b" ) ;
322
+ } ) ;
323
+ } ) ;
324
+
325
+ it ( "http.get redirecting to bracketed hostname" , function ( ) {
326
+ app . get ( "/a" , redirectsTo ( "http://[localhost]:3600/b" ) ) ;
327
+ app . get ( "/b" , sendsJson ( { a : "b" } ) ) ;
328
+
329
+ return server . start ( app )
330
+ . then ( asPromise ( function ( resolve , reject ) {
331
+ http . get ( "http://localhost:3600/a" , concatJson ( reject ) ) . on ( "error" , resolve ) ;
332
+ } ) )
333
+ . then ( function ( error ) {
334
+ assert ( error instanceof Error ) ;
335
+ assert . equal ( error . code , "ERR_FR_REDIRECTION_FAILURE" ) ;
336
+
337
+ var cause = error . cause ;
338
+ assert ( cause instanceof Error ) ;
339
+ assert ( cause instanceof TypeError ) ;
340
+ assert . equal ( cause . code , "ERR_INVALID_URL" ) ;
341
+ assert . equal ( cause . input , "http://[localhost]:3600/b" ) ;
342
+ } ) ;
343
+ } ) ;
344
+
244
345
it ( "http.get with response event" , function ( ) {
245
346
app . get ( "/a" , redirectsTo ( "/b" ) ) ;
246
347
app . get ( "/b" , redirectsTo ( "/c" ) ) ;
@@ -266,8 +367,8 @@ describe("follow-redirects", function () {
266
367
try {
267
368
http . get ( "/relative" ) ;
268
369
}
269
- catch ( e ) {
270
- error = e ;
370
+ catch ( err ) {
371
+ error = err ;
271
372
}
272
373
assert ( error instanceof Error ) ;
273
374
assert ( error instanceof TypeError ) ;
@@ -963,9 +1064,9 @@ describe("follow-redirects", function () {
963
1064
. then ( asPromise ( function ( resolve , reject ) {
964
1065
http . get ( "http://localhost:3600/a" )
965
1066
. on ( "response" , function ( ) { return reject ( new Error ( "unexpected response" ) ) ; } )
966
- . on ( "error" , reject ) ;
1067
+ . on ( "error" , resolve ) ;
967
1068
} ) )
968
- . catch ( function ( error ) {
1069
+ . then ( function ( error ) {
969
1070
assert ( error instanceof Error ) ;
970
1071
assert . equal ( error . message , "Redirected request failed: Unsupported protocol about:" ) ;
971
1072
@@ -1266,8 +1367,8 @@ describe("follow-redirects", function () {
1266
1367
try {
1267
1368
req . write ( 12345678 ) ;
1268
1369
}
1269
- catch ( e ) {
1270
- error = e ;
1370
+ catch ( err ) {
1371
+ error = err ;
1271
1372
}
1272
1373
req . destroy ( ) ;
1273
1374
assert ( error instanceof Error ) ;
@@ -2132,12 +2233,9 @@ describe("follow-redirects", function () {
2132
2233
throw new Error ( "no redirects!" ) ;
2133
2234
} ,
2134
2235
} ;
2135
- http . get ( options , concatJson ( resolve , reject ) ) . on ( "error" , reject ) ;
2236
+ http . get ( options , concatJson ( reject ) ) . on ( "error" , resolve ) ;
2136
2237
} ) )
2137
- . then ( function ( ) {
2138
- assert . fail ( "request chain should have been aborted" ) ;
2139
- } )
2140
- . catch ( function ( error ) {
2238
+ . then ( function ( error ) {
2141
2239
assert ( ! redirected ) ;
2142
2240
assert ( error instanceof Error ) ;
2143
2241
assert . equal ( error . message , "Redirected request failed: no redirects!" ) ;