Allows Content-Length for 304 Not Modified response (#2321)
This commit is contained in:
parent
9341f72b8d
commit
14332c5daf
|
|
@ -875,6 +875,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
|
||||||
var responseHeaders = HttpResponseHeaders;
|
var responseHeaders = HttpResponseHeaders;
|
||||||
|
|
||||||
if (!HttpMethods.IsHead(Method) &&
|
if (!HttpMethods.IsHead(Method) &&
|
||||||
|
StatusCode != StatusCodes.Status304NotModified &&
|
||||||
!responseHeaders.HasTransferEncoding &&
|
!responseHeaders.HasTransferEncoding &&
|
||||||
responseHeaders.ContentLength.HasValue &&
|
responseHeaders.ContentLength.HasValue &&
|
||||||
_responseBytesWritten < responseHeaders.ContentLength.Value)
|
_responseBytesWritten < responseHeaders.ContentLength.Value)
|
||||||
|
|
|
||||||
|
|
@ -2662,6 +2662,35 @@ namespace Microsoft.AspNetCore.Server.Kestrel.FunctionalTests
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public async Task NonZeroContentLengthFor304StatusCodeIsAllowed()
|
||||||
|
{
|
||||||
|
using (var server = new TestServer(httpContext =>
|
||||||
|
{
|
||||||
|
var response = httpContext.Response;
|
||||||
|
response.StatusCode = StatusCodes.Status304NotModified;
|
||||||
|
response.ContentLength = 42;
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
using (var connection = server.CreateConnection())
|
||||||
|
{
|
||||||
|
await connection.Send(
|
||||||
|
"GET / HTTP/1.1",
|
||||||
|
"Host:",
|
||||||
|
"",
|
||||||
|
"");
|
||||||
|
await connection.Receive(
|
||||||
|
"HTTP/1.1 304 Not Modified",
|
||||||
|
$"Date: {server.Context.DateHeaderValue}",
|
||||||
|
"Content-Length: 42",
|
||||||
|
"",
|
||||||
|
"");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static TheoryData<string, StringValues, string> NullHeaderData
|
public static TheoryData<string, StringValues, string> NullHeaderData
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue