@@ -204,7 +204,7 @@ describe('supports http with nodejs', function () {
204
204
assert . equal ( res . data , str ) ;
205
205
assert . equal ( res . request . path , '/two' ) ;
206
206
done ( ) ;
207
- } ) . catch ( done ) ; ;
207
+ } ) . catch ( done ) ;
208
208
} ) ;
209
209
} ) ;
210
210
@@ -223,7 +223,7 @@ describe('supports http with nodejs', function () {
223
223
assert . equal ( res . status , 302 ) ;
224
224
assert . equal ( res . headers [ 'location' ] , '/foo' ) ;
225
225
done ( ) ;
226
- } ) . catch ( done ) ; ;
226
+ } ) . catch ( done ) ;
227
227
} ) ;
228
228
} ) ;
229
229
@@ -241,7 +241,7 @@ describe('supports http with nodejs', function () {
241
241
assert . equal ( error . code , AxiosError . ERR_FR_TOO_MANY_REDIRECTS ) ;
242
242
assert . equal ( error . message , 'Maximum number of redirects exceeded' ) ;
243
243
done ( ) ;
244
- } ) ;
244
+ } ) . catch ( done ) ;
245
245
} ) ;
246
246
} ) ;
247
247
@@ -263,6 +263,56 @@ describe('supports http with nodejs', function () {
263
263
} ) . catch ( function ( error ) {
264
264
assert . equal ( error . message , 'Provided path is not allowed' ) ;
265
265
done ( ) ;
266
+ } ) . catch ( done ) ;
267
+ } ) ;
268
+ } ) ;
269
+
270
+ it ( 'should support beforeRedirect and proxy with redirect' , function ( done ) {
271
+ var requestCount = 0 ;
272
+ var totalRedirectCount = 5 ;
273
+ server = http . createServer ( function ( req , res ) {
274
+ requestCount += 1 ;
275
+ if ( requestCount <= totalRedirectCount ) {
276
+ res . setHeader ( 'Location' , 'http://localhost:4444' ) ;
277
+ res . writeHead ( 302 ) ;
278
+ }
279
+ res . end ( ) ;
280
+ } ) . listen ( 4444 , function ( ) {
281
+ var proxyUseCount = 0 ;
282
+ proxy = http . createServer ( function ( request , response ) {
283
+ proxyUseCount += 1 ;
284
+ var parsed = url . parse ( request . url ) ;
285
+ var opts = {
286
+ host : parsed . hostname ,
287
+ port : parsed . port ,
288
+ path : parsed . path
289
+ } ;
290
+
291
+ http . get ( opts , function ( res ) {
292
+ response . writeHead ( res . statusCode , res . headers ) ;
293
+ res . on ( 'data' , function ( data ) {
294
+ response . write ( data )
295
+ } ) ;
296
+ res . on ( 'end' , function ( ) {
297
+ response . end ( ) ;
298
+ } ) ;
299
+ } ) ;
300
+ } ) . listen ( 4000 , function ( ) {
301
+ var configBeforeRedirectCount = 0 ;
302
+ axios . get ( 'http://localhost:4444/' , {
303
+ proxy : {
304
+ host : 'localhost' ,
305
+ port : 4000
306
+ } ,
307
+ maxRedirects : totalRedirectCount ,
308
+ beforeRedirect : function ( options ) {
309
+ configBeforeRedirectCount += 1 ;
310
+ }
311
+ } ) . then ( function ( res ) {
312
+ assert . equal ( totalRedirectCount , configBeforeRedirectCount , 'should invoke config.beforeRedirect option on every redirect' ) ;
313
+ assert . equal ( totalRedirectCount + 1 , proxyUseCount , 'should go through proxy on every redirect' ) ;
314
+ done ( ) ;
315
+ } ) . catch ( done ) ;
266
316
} ) ;
267
317
} ) ;
268
318
} ) ;
0 commit comments