@@ -474,3 +474,64 @@ test('Issue#2415', async (t) => {
474
474
475
475
t . doesNotThrow ( ( ) => new Headers ( response . headers ) )
476
476
} )
477
+
478
+ test ( 'Issue #2386' , async t => {
479
+ const server = createSecureServer ( pem )
480
+ const body = Buffer . from ( 'hello' )
481
+ const requestChunks = [ ]
482
+ const expectedResponseBody = { hello : 'h2' }
483
+ const controller = new AbortController ( )
484
+ const signal = controller . signal
485
+
486
+ server . on ( 'stream' , async ( stream , headers ) => {
487
+ t . equal ( headers [ ':method' ] , 'PUT' )
488
+ t . equal ( headers [ ':path' ] , '/' )
489
+ t . equal ( headers [ ':scheme' ] , 'https' )
490
+
491
+ stream . on ( 'data' , chunk => requestChunks . push ( chunk ) )
492
+
493
+ stream . respond ( {
494
+ 'content-type' : 'application/json' ,
495
+ 'x-custom-h2' : headers [ 'x-my-header' ] ,
496
+ ':status' : 200
497
+ } )
498
+
499
+ stream . end ( JSON . stringify ( expectedResponseBody ) )
500
+ } )
501
+
502
+ t . plan ( 3 )
503
+
504
+ server . listen ( 0 )
505
+ await once ( server , 'listening' )
506
+
507
+ const client = new Client ( `https://localhost:${ server . address ( ) . port } ` , {
508
+ connect : {
509
+ rejectUnauthorized : false
510
+ } ,
511
+ allowH2 : true
512
+ } )
513
+
514
+ t . teardown ( server . close . bind ( server ) )
515
+ t . teardown ( client . close . bind ( client ) )
516
+
517
+ try {
518
+ await fetch (
519
+ `https://localhost:${ server . address ( ) . port } /` ,
520
+ // Needs to be passed to disable the reject unauthorized
521
+ {
522
+ body,
523
+ signal,
524
+ method : 'PUT' ,
525
+ dispatcher : client ,
526
+ headers : {
527
+ 'x-my-header' : 'foo' ,
528
+ 'content-type' : 'text-plain'
529
+ }
530
+ }
531
+ )
532
+
533
+ controller . abort ( )
534
+ } catch ( error ) {
535
+ t . error ( error )
536
+ }
537
+ } )
0 commit comments