@@ -51,6 +51,46 @@ test('should decompress gzip response', async t => {
5151 await t . completed
5252} )
5353
54+ test ( 'should preserve trailers when decompressing response' , async t => {
55+ const data = 'Response with trailers'
56+ const compressed = gzipSync ( data )
57+ const server = createServer ( { joinDuplicateHeaders : true } , ( _req , res ) => {
58+ res . writeHead ( 200 , {
59+ 'Content-Encoding' : 'gzip' ,
60+ Trailer : 'X-Checksum'
61+ } )
62+ res . addTrailers ( { 'X-Checksum' : 'verified' } )
63+ res . end ( compressed )
64+ } )
65+
66+ server . listen ( 0 )
67+ await once ( server , 'listening' )
68+
69+ const client = new Client (
70+ `http://localhost:${ server . address ( ) . port } `
71+ ) . compose ( interceptors . decompress ( ) )
72+
73+ after ( async ( ) => {
74+ await client . close ( )
75+ server . close ( )
76+ await once ( server , 'close' )
77+ } )
78+
79+ t = tspl ( t , { plan : 2 } )
80+
81+ const response = await client . request ( {
82+ method : 'GET' ,
83+ path : '/' ,
84+ headers : { TE : 'trailers' }
85+ } )
86+ const body = await response . body . text ( )
87+
88+ t . equal ( body , data )
89+ t . deepEqual ( response . trailers , { 'x-checksum' : 'verified' } )
90+
91+ await t . completed
92+ } )
93+
5494test ( 'should preserve representation headers and empty body for HEAD responses' , async t => {
5595 const compressedRepresentation = gzipSync ( 'HEAD response representation' )
5696 const server = createServer ( { joinDuplicateHeaders : true } , ( req , res ) => {
@@ -614,7 +654,7 @@ test('should allow custom skipStatusCodes', async t => {
614654} )
615655
616656test ( 'should decompress multiple encodings in correct order' , async t => {
617- t = tspl ( t , { plan : 3 } )
657+ t = tspl ( t , { plan : 4 } )
618658
619659 const server = createServer ( { joinDuplicateHeaders : true } , async ( req , res ) => {
620660 // First compress with gzip, then with deflate (gzip, deflate)
@@ -623,14 +663,16 @@ test('should decompress multiple encodings in correct order', async t => {
623663
624664 res . writeHead ( 200 , {
625665 'Content-Type' : 'text/plain' ,
626- 'Content-Encoding' : 'gzip, deflate' // Applied in this order
666+ 'Content-Encoding' : 'gzip, deflate' , // Applied in this order
667+ Trailer : 'X-Checksum'
627668 } )
628669
629670 const data = 'Multiple encoding test message'
630671
631672 // Pipe: data → gzip → deflate → response
632673 gzip . pipe ( deflate )
633674 deflate . pipe ( res )
675+ res . addTrailers ( { 'X-Checksum' : 'verified' } )
634676 gzip . end ( data )
635677 } )
636678
@@ -649,14 +691,16 @@ test('should decompress multiple encodings in correct order', async t => {
649691
650692 const response = await client . request ( {
651693 method : 'GET' ,
652- path : '/'
694+ path : '/' ,
695+ headers : { TE : 'trailers' }
653696 } )
654697
655698 const body = await response . body . text ( )
656699
657700 t . equal ( response . statusCode , 200 )
658701 t . equal ( response . headers [ 'content-encoding' ] , undefined ) // Should be removed
659702 t . equal ( body , 'Multiple encoding test message' ) // Should be fully decompressed
703+ t . deepEqual ( response . trailers , { 'x-checksum' : 'verified' } )
660704
661705 await t . completed
662706} )
0 commit comments