@@ -565,6 +565,41 @@ describe('UwsResponse', () => {
565565 } ) ;
566566 } ) ;
567567
568+ describe ( 'HEAD request handling' , ( ) => {
569+ it ( 'should suppress body for HEAD request with content-length' , ( ) => {
570+ res = createResponse ( ) ;
571+ const mockReq = { method : 'HEAD' } as any ;
572+ res . bindRequest ( mockReq ) ;
573+
574+ res . setHeader ( 'content-length' , '1024' ) . send ( 'Hello' ) ;
575+
576+ expect ( mockUwsRes . endWithoutBody ) . toHaveBeenCalledWith ( 1024 ) ;
577+ expect ( mockUwsRes . end ) . not . toHaveBeenCalled ( ) ;
578+ } ) ;
579+
580+ it ( 'should suppress body for HEAD request without content-length' , ( ) => {
581+ res = createResponse ( ) ;
582+ const mockReq = { method : 'HEAD' } as any ;
583+ res . bindRequest ( mockReq ) ;
584+
585+ res . send ( 'Hello' ) ;
586+
587+ expect ( mockUwsRes . end ) . toHaveBeenCalledWith ( ) ;
588+ expect ( mockUwsRes . endWithoutBody ) . not . toHaveBeenCalled ( ) ;
589+ } ) ;
590+
591+ it ( 'should send body normally for GET request' , ( ) => {
592+ res = createResponse ( ) ;
593+ const mockReq = { method : 'GET' } as any ;
594+ res . bindRequest ( mockReq ) ;
595+
596+ res . send ( 'Hello' ) ;
597+
598+ expect ( mockUwsRes . end ) . toHaveBeenCalledWith ( 'Hello' ) ;
599+ expect ( mockUwsRes . endWithoutBody ) . not . toHaveBeenCalled ( ) ;
600+ } ) ;
601+ } ) ;
602+
568603 describe ( 'json()' , ( ) => {
569604 beforeEach ( ( ) => {
570605 res = createResponse ( ) ;
0 commit comments