@@ -298,6 +298,74 @@ describe('retries', () => {
298
298
expect ( count ) . toEqual ( 3 ) ;
299
299
} ) ;
300
300
301
+ test ( 'omit retry count header' , async ( ) => {
302
+ let count = 0 ;
303
+ let capturedRequest : RequestInit | undefined ;
304
+ const testFetch = async ( url : RequestInfo , init : RequestInit = { } ) : Promise < Response > => {
305
+ count ++ ;
306
+ if ( count <= 2 ) {
307
+ return new Response ( undefined , {
308
+ status : 429 ,
309
+ headers : {
310
+ 'Retry-After' : '0.1' ,
311
+ } ,
312
+ } ) ;
313
+ }
314
+ capturedRequest = init ;
315
+ return new Response ( JSON . stringify ( { a : 1 } ) , { headers : { 'Content-Type' : 'application/json' } } ) ;
316
+ } ;
317
+ const client = new Mux ( {
318
+ tokenId : 'my token id' ,
319
+ tokenSecret : 'my secret' ,
320
+ fetch : testFetch ,
321
+ maxRetries : 4 ,
322
+ } ) ;
323
+
324
+ expect (
325
+ await client . request ( {
326
+ path : '/foo' ,
327
+ method : 'get' ,
328
+ headers : { 'X-Stainless-Retry-Count' : null } ,
329
+ } ) ,
330
+ ) . toEqual ( { a : 1 } ) ;
331
+
332
+ expect ( capturedRequest ! . headers as Headers ) . not . toHaveProperty ( 'x-stainless-retry-count' ) ;
333
+ } ) ;
334
+
335
+ test ( 'overwrite retry count header' , async ( ) => {
336
+ let count = 0 ;
337
+ let capturedRequest : RequestInit | undefined ;
338
+ const testFetch = async ( url : RequestInfo , init : RequestInit = { } ) : Promise < Response > => {
339
+ count ++ ;
340
+ if ( count <= 2 ) {
341
+ return new Response ( undefined , {
342
+ status : 429 ,
343
+ headers : {
344
+ 'Retry-After' : '0.1' ,
345
+ } ,
346
+ } ) ;
347
+ }
348
+ capturedRequest = init ;
349
+ return new Response ( JSON . stringify ( { a : 1 } ) , { headers : { 'Content-Type' : 'application/json' } } ) ;
350
+ } ;
351
+ const client = new Mux ( {
352
+ tokenId : 'my token id' ,
353
+ tokenSecret : 'my secret' ,
354
+ fetch : testFetch ,
355
+ maxRetries : 4 ,
356
+ } ) ;
357
+
358
+ expect (
359
+ await client . request ( {
360
+ path : '/foo' ,
361
+ method : 'get' ,
362
+ headers : { 'X-Stainless-Retry-Count' : '42' } ,
363
+ } ) ,
364
+ ) . toEqual ( { a : 1 } ) ;
365
+
366
+ expect ( ( capturedRequest ! . headers as Headers ) [ 'x-stainless-retry-count' ] ) . toBe ( '42' ) ;
367
+ } ) ;
368
+
301
369
test ( 'retry on 429 with retry-after' , async ( ) => {
302
370
let count = 0 ;
303
371
const testFetch = async ( url : RequestInfo , { signal } : RequestInit = { } ) : Promise < Response > => {
0 commit comments