@@ -337,6 +337,80 @@ describe('CompressionHandler', () => {
337337 expect ( setHeaderSpy ) . toHaveBeenCalledWith ( 'content-encoding' , 'deflate' ) ;
338338 } ) ;
339339
340+ it ( 'should compress response when Accept-Encoding is wildcard (*)' , ( ) => {
341+ const handler = new CompressionHandler ( { brotli : true } ) ;
342+ setupMock ( '*' , 'text/plain' ) ;
343+
344+ const stream = handler . createCompressionStream (
345+ mockReq as UwsRequest ,
346+ mockRes as UwsResponse ,
347+ LARGE_DATA
348+ ) ;
349+
350+ expect ( stream ) . toBeInstanceOf ( Transform ) ;
351+ // Should pick brotli as highest priority supported encoding
352+ expect ( setHeaderSpy ) . toHaveBeenCalledWith ( 'content-encoding' , 'br' ) ;
353+ } ) ;
354+
355+ it ( 'should expand wildcard to supported encodings not explicitly listed' , ( ) => {
356+ const handler = new CompressionHandler ( ) ;
357+ setupMock ( 'gzip, *' , 'text/plain' ) ;
358+
359+ const stream = handler . createCompressionStream (
360+ mockReq as UwsRequest ,
361+ mockRes as UwsResponse ,
362+ LARGE_DATA
363+ ) ;
364+
365+ expect ( stream ) . toBeInstanceOf ( Transform ) ;
366+ // gzip explicitly listed with higher priority than wildcard-expanded encodings
367+ expect ( setHeaderSpy ) . toHaveBeenCalledWith ( 'content-encoding' , 'gzip' ) ;
368+ } ) ;
369+
370+ it ( 'should respect explicitly rejected encodings with wildcard' , ( ) => {
371+ const handler = new CompressionHandler ( ) ;
372+ setupMock ( 'gzip;q=0, *' , 'text/plain' ) ;
373+
374+ const stream = handler . createCompressionStream (
375+ mockReq as UwsRequest ,
376+ mockRes as UwsResponse ,
377+ LARGE_DATA
378+ ) ;
379+
380+ expect ( stream ) . toBeInstanceOf ( Transform ) ;
381+ // gzip rejected (q=0), wildcard should expand to deflate only (brotli not enabled)
382+ expect ( setHeaderSpy ) . toHaveBeenCalledWith ( 'content-encoding' , 'deflate' ) ;
383+ } ) ;
384+
385+ it ( 'should respect explicitly rejected encodings with wildcard when brotli enabled' , ( ) => {
386+ const handler = new CompressionHandler ( { brotli : true } ) ;
387+ setupMock ( 'gzip;q=0, *' , 'text/plain' ) ;
388+
389+ const stream = handler . createCompressionStream (
390+ mockReq as UwsRequest ,
391+ mockRes as UwsResponse ,
392+ LARGE_DATA
393+ ) ;
394+
395+ expect ( stream ) . toBeInstanceOf ( Transform ) ;
396+ // gzip rejected (q=0), wildcard expands to br and deflate
397+ // br has highest priority
398+ expect ( setHeaderSpy ) . toHaveBeenCalledWith ( 'content-encoding' , 'br' ) ;
399+ } ) ;
400+
401+ it ( 'should return null for wildcard with all supported encodings rejected' , ( ) => {
402+ const handler = new CompressionHandler ( ) ;
403+ setupMock ( 'gzip;q=0, deflate;q=0, *;q=0' , 'text/plain' ) ;
404+
405+ const stream = handler . createCompressionStream (
406+ mockReq as UwsRequest ,
407+ mockRes as UwsResponse ,
408+ LARGE_DATA
409+ ) ;
410+
411+ expect ( stream ) . toBeNull ( ) ;
412+ } ) ;
413+
340414 it ( 'should create stream without body check when body not provided' , ( ) => {
341415 const handler = new CompressionHandler ( ) ;
342416 setupMock ( 'gzip' , 'text/plain' ) ;
0 commit comments