Skip to content

Make kestrel not use the modified Http Protocol #18322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
1 commit merged into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ internal partial class HttpProtocol : IHttpRequestFeature,

string IHttpRequestFeature.Protocol
{
get => HttpVersion;
set => HttpVersion = value;
get => _httpProtocol ??= HttpVersion;
set => _httpProtocol = value;
}

string IHttpRequestFeature.Scheme
Expand Down
4 changes: 4 additions & 0 deletions src/Servers/Kestrel/Core/src/Internal/Http/HttpProtocol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ internal abstract partial class HttpProtocol : IHttpResponseControl
private BadHttpRequestException _requestRejectedException;

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

private string _requestId;
private int _requestHeadersParsed;
Expand Down Expand Up @@ -351,6 +354,7 @@ public void Reset()
RawTarget = null;
QueryString = null;
_httpVersion = Http.HttpVersion.Unknown;
_httpProtocol = null;
_statusCode = StatusCodes.Status200OK;
_reasonPhrase = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,42 @@ await connection.ReceiveEnd(
}
}

[Fact]
public async Task IgnoresChangesToHttpProtocol()
{
var testContext = new TestServiceContext(LoggerFactory);

await using (var server = new TestServer(async httpContext =>
{
httpContext.Request.Protocol = "HTTP/2"; // Doesn't support chunking. This change should be ignored.
var response = httpContext.Response;
await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("Hello "), 0, 6));
await response.BodyWriter.WriteAsync(new Memory<byte>(Encoding.ASCII.GetBytes("World!"), 0, 6));
}, testContext))
{
using (var connection = server.CreateConnection())
{
await connection.Send(
"GET / HTTP/1.1",
"Host:",
"",
"");
await connection.Receive(
"HTTP/1.1 200 OK",
$"Date: {testContext.DateHeaderValue}",
"Transfer-Encoding: chunked",
"",
"6",
"Hello ",
"6",
"World!",
"0",
"",
"");
}
}
}

[Fact]
public async Task ResponsesAreChunkedAutomaticallyForHttp11NonKeepAliveRequests()
{
Expand Down