File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import test from 'ava';
4
4
import * as pEvent from 'p-event' ;
5
5
import * as getStream from 'get-stream' ;
6
6
import { Handler } from 'express' ;
7
+ import * as nock from 'nock' ;
7
8
import CacheableLookup from 'cacheable-lookup' ;
8
9
import * as delay from 'delay' ;
9
10
import got , { CacheError , Response } from '../source/index' ;
@@ -375,3 +376,27 @@ test('http-cache-semantics typings', t => {
375
376
376
377
t . is ( instance . defaults . options . cacheOptions . shared , false ) ;
377
378
} ) ;
379
+
380
+ test ( 'allows internal modifications' , async t => {
381
+ nock ( 'http://example.com' ) . get ( '/test' ) . reply ( 401 ) ;
382
+ nock ( 'http://example.com' ) . get ( '/test' ) . reply ( 200 , JSON . stringify ( {
383
+ wat : [ '123' ]
384
+ } ) ) ;
385
+
386
+ const client = got . extend ( {
387
+ cache : new Map ( ) ,
388
+ hooks : {
389
+ afterResponse : [
390
+ async ( response , retryWithMergedOptions ) => {
391
+ if ( response . statusCode === 401 ) {
392
+ return retryWithMergedOptions ( { } ) ;
393
+ }
394
+
395
+ return response ;
396
+ }
397
+ ]
398
+ }
399
+ } ) ;
400
+
401
+ await t . notThrowsAsync ( client . get ( 'http://example.com/test' ) ) ;
402
+ } ) ;
You can’t perform that action at this time.
0 commit comments