@@ -441,6 +441,7 @@ class Parser {
441441
442442 this . keepAlive = ''
443443 this . contentLength = ''
444+ this . connection = ''
444445 this . maxResponseSize = client [ kMaxResponseSize ]
445446 }
446447
@@ -616,6 +617,8 @@ class Parser {
616617 const key = this . headers [ len - 2 ]
617618 if ( key . length === 10 && key . toString ( ) . toLowerCase ( ) === 'keep-alive' ) {
618619 this . keepAlive += buf . toString ( )
620+ } else if ( key . length === 10 && key . toString ( ) . toLowerCase ( ) === 'connection' ) {
621+ this . connection += buf . toString ( )
619622 } else if ( key . length === 14 && key . toString ( ) . toLowerCase ( ) === 'content-length' ) {
620623 this . contentLength += buf . toString ( )
621624 }
@@ -709,7 +712,11 @@ class Parser {
709712 assert . strictEqual ( this . timeoutType , TIMEOUT_HEADERS )
710713
711714 this . statusCode = statusCode
712- this . shouldKeepAlive = shouldKeepAlive
715+ this . shouldKeepAlive = (
716+ shouldKeepAlive ||
717+ // Override llhttp value which does not allow keepAlive for HEAD.
718+ ( request . method === 'HEAD' && ! socket [ kReset ] && this . connection . toLowerCase ( ) === 'keep-alive' )
719+ )
713720
714721 if ( this . statusCode >= 200 ) {
715722 const bodyTimeout = request . bodyTimeout != null
@@ -739,7 +746,7 @@ class Parser {
739746 this . headers = [ ]
740747 this . headersSize = 0
741748
742- if ( shouldKeepAlive && client [ kPipelining ] ) {
749+ if ( this . shouldKeepAlive && client [ kPipelining ] ) {
743750 const keepAliveTimeout = this . keepAlive ? util . parseKeepAliveTimeout ( this . keepAlive ) : null
744751
745752 if ( keepAliveTimeout != null ) {
@@ -769,7 +776,6 @@ class Parser {
769776 }
770777
771778 if ( request . method === 'HEAD' ) {
772- assert ( socket [ kReset ] )
773779 return 1
774780 }
775781
@@ -843,6 +849,7 @@ class Parser {
843849 this . bytesRead = 0
844850 this . contentLength = ''
845851 this . keepAlive = ''
852+ this . connection = ''
846853
847854 assert ( this . headers . length % 2 === 0 )
848855 this . headers = [ ]
@@ -1376,8 +1383,8 @@ function write (client, request) {
13761383 socket [ kReset ] = true
13771384 }
13781385
1379- if ( reset ) {
1380- socket [ kReset ] = true
1386+ if ( reset != null ) {
1387+ socket [ kReset ] = reset
13811388 }
13821389
13831390 if ( client [ kMaxRequests ] && socket [ kCounter ] ++ >= client [ kMaxRequests ] ) {
0 commit comments