Allows Content-Length for 304 Not Modified response (#2321)

This commit is contained in:
Alessio Franceschelli 2018-02-15 00:01:07 +00:00 committed by Chris Ross
parent 9341f72b8d
commit 14332c5daf
2 changed files with 30 additions and 0 deletions

View File

@ -875,6 +875,7 @@ namespace Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http
var responseHeaders = HttpResponseHeaders;
if (!HttpMethods.IsHead(Method) &&
StatusCode != StatusCodes.Status304NotModified &&
!responseHeaders.HasTransferEncoding &&
responseHeaders.ContentLength.HasValue &&
_responseBytesWritten < responseHeaders.ContentLength.Value)

View File

@ -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
{
get