@@ -729,36 +729,37 @@ private void CreateResponseHeader(
729
729
730
730
if ( _keepAlive && ! responseHeaders . HasTransferEncoding && ! responseHeaders . HasContentLength )
731
731
{
732
- if ( appCompleted )
732
+ // Don't set the Content-Length or Transfer-Encoding headers
733
+ // automatically for HEAD requests or 101, 204, 205, 304 responses.
734
+ if ( Method != "HEAD" && StatusCanHaveBody ( StatusCode ) )
733
735
{
734
- // Don't set the Content-Length or Transfer-Encoding headers
735
- // automatically for HEAD requests or 101, 204, 205, 304 responses.
736
- if ( Method != "HEAD" && StatusCanHaveBody ( StatusCode ) )
736
+ if ( appCompleted )
737
737
{
738
738
// Since the app has completed and we are only now generating
739
739
// the headers we can safely set the Content-Length to 0.
740
740
responseHeaders . SetRawContentLength ( "0" , _bytesContentLengthZero ) ;
741
741
}
742
- }
743
- else
744
- {
745
- // Note for future reference: never change this to set _autoChunk to true on HTTP/1.0
746
- // connections, even if we were to infer the client supports it because an HTTP/1.0 request
747
- // was received that used chunked encoding. Sending a chunked response to an HTTP/1.0
748
- // client would break compliance with RFC 7230 (section 3.3.1):
749
- //
750
- // A server MUST NOT send a response containing Transfer-Encoding unless the corresponding
751
- // request indicates HTTP/1.1 (or later).
752
- if ( _httpVersion == HttpVersionType . Http11 )
753
- {
754
- _autoChunk = true ;
755
- responseHeaders . SetRawTransferEncoding ( "chunked" , _bytesTransferEncodingChunked ) ;
756
- }
757
742
else
758
743
{
759
- _keepAlive = false ;
744
+ // Note for future reference: never change this to set _autoChunk to true on HTTP/1.0
745
+ // connections, even if we were to infer the client supports it because an HTTP/1.0 request
746
+ // was received that used chunked encoding. Sending a chunked response to an HTTP/1.0
747
+ // client would break compliance with RFC 7230 (section 3.3.1):
748
+ //
749
+ // A server MUST NOT send a response containing Transfer-Encoding unless the corresponding
750
+ // request indicates HTTP/1.1 (or later).
751
+ if ( _httpVersion == HttpVersionType . Http11 )
752
+ {
753
+ _autoChunk = true ;
754
+ responseHeaders . SetRawTransferEncoding ( "chunked" , _bytesTransferEncodingChunked ) ;
755
+ }
760
756
}
761
757
}
758
+
759
+ if ( ! appCompleted && _httpVersion != HttpVersionType . Http11 )
760
+ {
761
+ _keepAlive = false ;
762
+ }
762
763
}
763
764
764
765
if ( ! _keepAlive && ! hasConnection && _httpVersion != HttpVersionType . Http10 )
0 commit comments