Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 14332c5

Browse files
alefranzTratcher
authored andcommitted
Allows Content-Length for 304 Not Modified response (#2321)
1 parent 9341f72 commit 14332c5

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Kestrel.Core/Internal/Http/HttpProtocol.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,7 @@ protected void VerifyResponseContentLength()
875875
var responseHeaders = HttpResponseHeaders;
876876

877877
if (!HttpMethods.IsHead(Method) &&
878+
StatusCode != StatusCodes.Status304NotModified &&
878879
!responseHeaders.HasTransferEncoding &&
879880
responseHeaders.ContentLength.HasValue &&
880881
_responseBytesWritten < responseHeaders.ContentLength.Value)

test/Kestrel.FunctionalTests/ResponseTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2662,6 +2662,35 @@ public async Task HttpsConnectionClosedWhenResponseDoesNotSatisfyMinimumDataRate
26622662
}
26632663
}
26642664

2665+
[Fact]
2666+
public async Task NonZeroContentLengthFor304StatusCodeIsAllowed()
2667+
{
2668+
using (var server = new TestServer(httpContext =>
2669+
{
2670+
var response = httpContext.Response;
2671+
response.StatusCode = StatusCodes.Status304NotModified;
2672+
response.ContentLength = 42;
2673+
2674+
return Task.CompletedTask;
2675+
}))
2676+
{
2677+
using (var connection = server.CreateConnection())
2678+
{
2679+
await connection.Send(
2680+
"GET / HTTP/1.1",
2681+
"Host:",
2682+
"",
2683+
"");
2684+
await connection.Receive(
2685+
"HTTP/1.1 304 Not Modified",
2686+
$"Date: {server.Context.DateHeaderValue}",
2687+
"Content-Length: 42",
2688+
"",
2689+
"");
2690+
}
2691+
}
2692+
}
2693+
26652694
public static TheoryData<string, StringValues, string> NullHeaderData
26662695
{
26672696
get

0 commit comments

Comments
 (0)