@@ -41,7 +41,6 @@ public abstract partial class Frame : IFrameControl
41
41
private static readonly byte [ ] _bytesConnectionKeepAlive = Encoding . ASCII . GetBytes ( "\r \n Connection: keep-alive" ) ;
42
42
private static readonly byte [ ] _bytesTransferEncodingChunked = Encoding . ASCII . GetBytes ( "\r \n Transfer-Encoding: chunked" ) ;
43
43
private static readonly byte [ ] _bytesHttpVersion11 = Encoding . ASCII . GetBytes ( "HTTP/1.1 " ) ;
44
- private static readonly byte [ ] _bytesContentLengthZero = Encoding . ASCII . GetBytes ( "\r \n Content-Length: 0" ) ;
45
44
private static readonly byte [ ] _bytesEndHeaders = Encoding . ASCII . GetBytes ( "\r \n \r \n " ) ;
46
45
private static readonly byte [ ] _bytesServer = Encoding . ASCII . GetBytes ( "\r \n Server: Kestrel" ) ;
47
46
@@ -657,12 +656,12 @@ private void VerifyAndUpdateWrite(int count)
657
656
658
657
if ( responseHeaders != null &&
659
658
! responseHeaders . HasTransferEncoding &&
660
- responseHeaders . HasContentLength &&
661
- _responseBytesWritten + count > responseHeaders . HeaderContentLengthValue . Value )
659
+ responseHeaders . ContentLength . HasValue &&
660
+ _responseBytesWritten + count > responseHeaders . ContentLength . Value )
662
661
{
663
662
_keepAlive = false ;
664
663
throw new InvalidOperationException (
665
- $ "Response Content-Length mismatch: too many bytes written ({ _responseBytesWritten + count } of { responseHeaders . HeaderContentLengthValue . Value } ).") ;
664
+ $ "Response Content-Length mismatch: too many bytes written ({ _responseBytesWritten + count } of { responseHeaders . ContentLength . Value } ).") ;
666
665
}
667
666
668
667
_responseBytesWritten += count ;
@@ -679,8 +678,8 @@ private void CheckLastWrite()
679
678
// Called after VerifyAndUpdateWrite(), so _responseBytesWritten has already been updated.
680
679
if ( responseHeaders != null &&
681
680
! responseHeaders . HasTransferEncoding &&
682
- responseHeaders . HasContentLength &&
683
- _responseBytesWritten == responseHeaders . HeaderContentLengthValue . Value )
681
+ responseHeaders . ContentLength . HasValue &&
682
+ _responseBytesWritten == responseHeaders . ContentLength . Value )
684
683
{
685
684
_abortedCts = null ;
686
685
}
@@ -692,8 +691,8 @@ protected void VerifyResponseContentLength()
692
691
693
692
if ( ! HttpMethods . IsHead ( Method ) &&
694
693
! responseHeaders . HasTransferEncoding &&
695
- responseHeaders . HeaderContentLengthValue . HasValue &&
696
- _responseBytesWritten < responseHeaders . HeaderContentLengthValue . Value )
694
+ responseHeaders . ContentLength . HasValue &&
695
+ _responseBytesWritten < responseHeaders . ContentLength . Value )
697
696
{
698
697
// We need to close the connection if any bytes were written since the client
699
698
// cannot be certain of how many bytes it will receive.
@@ -703,7 +702,7 @@ protected void VerifyResponseContentLength()
703
702
}
704
703
705
704
ReportApplicationError ( new InvalidOperationException (
706
- $ "Response Content-Length mismatch: too few bytes written ({ _responseBytesWritten } of { responseHeaders . HeaderContentLengthValue . Value } ).") ) ;
705
+ $ "Response Content-Length mismatch: too few bytes written ({ _responseBytesWritten } of { responseHeaders . ContentLength . Value } ).") ) ;
707
706
}
708
707
}
709
708
@@ -920,13 +919,13 @@ private void CreateResponseHeader(
920
919
// automatically for HEAD requests or 204, 205, 304 responses.
921
920
if ( _canHaveBody )
922
921
{
923
- if ( ! hasTransferEncoding && ! responseHeaders . HasContentLength )
922
+ if ( ! hasTransferEncoding && ! responseHeaders . ContentLength . HasValue )
924
923
{
925
924
if ( appCompleted && StatusCode != StatusCodes . Status101SwitchingProtocols )
926
925
{
927
926
// Since the app has completed and we are only now generating
928
927
// the headers we can safely set the Content-Length to 0.
929
- responseHeaders . SetRawContentLength ( "0" , _bytesContentLengthZero ) ;
928
+ responseHeaders . ContentLength = 0 ;
930
929
}
931
930
else
932
931
{
@@ -1468,7 +1467,7 @@ private void SetErrorResponseHeaders(int statusCode)
1468
1467
var dateHeaderValues = DateHeaderValueManager . GetDateHeaderValues ( ) ;
1469
1468
1470
1469
responseHeaders . SetRawDate ( dateHeaderValues . String , dateHeaderValues . Bytes ) ;
1471
- responseHeaders . SetRawContentLength ( "0" , _bytesContentLengthZero ) ;
1470
+ responseHeaders . ContentLength = 0 ;
1472
1471
1473
1472
if ( ServerOptions . AddServerHeader )
1474
1473
{
0 commit comments