@@ -607,6 +607,14 @@ function statusIsInformational(status) {
607
607
return ( status < 200 && status >= 100 && status !== 101 ) ;
608
608
}
609
609
610
+ function responseCannotContainMessageBody ( status , method ) {
611
+ // RFC9112 Section 6.1.1
612
+ return method === 'HEAD'
613
+ || status === 204
614
+ || status === 304
615
+ || statusIsInformational ( status )
616
+ }
617
+
610
618
// client
611
619
function parserOnIncomingClient ( res , shouldKeepAlive ) {
612
620
const socket = this . socket ;
@@ -654,11 +662,19 @@ function parserOnIncomingClient(res, shouldKeepAlive) {
654
662
return 1 ; // Skip body but don't treat as Upgrade.
655
663
}
656
664
657
- if ( req . shouldKeepAlive && ! shouldKeepAlive && ! req . upgradeOrConnect ) {
665
+ if ( req . shouldKeepAlive && ! req . upgradeOrConnect ) {
658
666
// Server MUST respond with Connection:keep-alive for us to enable it.
659
667
// If we've been upgraded (via WebSockets) we also shouldn't try to
660
668
// keep the connection open.
661
- req . shouldKeepAlive = false ;
669
+ if ( ! shouldKeepAlive ) {
670
+ req . shouldKeepAlive = false ;
671
+ }
672
+
673
+ // Socket will be kept alive and response cannot contain
674
+ // a message body, resume to allow socket to return to free pool
675
+ else if ( responseCannotContainMessageBody ( res . statusCode , method ) ) {
676
+ res . resume ( )
677
+ }
662
678
}
663
679
664
680
if ( req [ kClientRequestStatistics ] && hasObserver ( 'http' ) ) {
0 commit comments