Skip to content

Commit 6dd3d6e

Browse files
Tratchermsftbot[bot]
authored andcommitted
Make kestrel not use the modified Http Protocol #17975 (#18322)
1 parent c9829d0 commit 6dd3d6e

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ internal partial class HttpProtocol : IHttpRequestFeature,
3737

3838
string IHttpRequestFeature.Protocol
3939
{
40-
get => HttpVersion;
41-
set => HttpVersion = value;
40+
get => _httpProtocol ??= HttpVersion;
41+
set => _httpProtocol = value;
4242
}
4343

4444
string IHttpRequestFeature.Scheme

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ internal abstract partial class HttpProtocol : IHttpResponseControl
5757
private BadHttpRequestException _requestRejectedException;
5858

5959
protected HttpVersion _httpVersion;
60+
// This should only be used by the application, not the server. This is settable on HttpRequest but we don't want that to affect
61+
// how Kestrel processes requests/responses.
62+
private string _httpProtocol;
6063

6164
private string _requestId;
6265
private int _requestHeadersParsed;
@@ -351,6 +354,7 @@ public void Reset()
351354
RawTarget = null;
352355
QueryString = null;
353356
_httpVersion = Http.HttpVersion.Unknown;
357+
_httpProtocol = null;
354358
_statusCode = StatusCodes.Status200OK;
355359
_reasonPhrase = null;
356360

src/Servers/Kestrel/test/InMemory.FunctionalTests/ChunkedResponseTests.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,42 @@ await connection.ReceiveEnd(
7878
}
7979
}
8080

81+
[Fact]
82+
public async Task IgnoresChangesToHttpProtocol()
83+
{
84+
var testContext = new TestServiceContext(LoggerFactory);
85+
86+
await using (var server = new TestServer(async httpContext =>
87+
{
88+
httpContext.Request.Protocol = "HTTP/2"; // Doesn't support chunking. This change should be ignored.
89+
var response = httpContext.Response;
90+
await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello "), 0, 6));
91+
await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("World!"), 0, 6));
92+
}, testContext))
93+
{
94+
using (var connection = server.CreateConnection())
95+
{
96+
await connection.Send(
97+
"GET / HTTP/1.1",
98+
"Host:",
99+
"",
100+
"");
101+
await connection.Receive(
102+
"HTTP/1.1 200 OK",
103+
$"Date: {testContext.DateHeaderValue}",
104+
"Transfer-Encoding: chunked",
105+
"",
106+
"6",
107+
"Hello ",
108+
"6",
109+
"World!",
110+
"0",
111+
"",
112+
"");
113+
}
114+
}
115+
}
116+
81117
[Fact]
82118
public async Task ResponsesAreChunkedAutomaticallyForHttp11NonKeepAliveRequests()
83119
{

0 commit comments

Comments
 (0)