-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Detect HTTP/1.1 on HTTP/2 connection #39358
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d5b12ae
Detect HTTP version on invalid HTTP/2 connection
JamesNK 5c40e68
Clean up
JamesNK 8b2d98e
Return 400 response
JamesNK 13c7bac
Update src/Servers/Kestrel/Core/src/Internal/Http2/Http2Connection.cs
JamesNK c1e5d77
Tests
JamesNK 4604e9b
Fix build
JamesNK 0b7abc3
PR feedback
JamesNK b8e05fe
Clean up
JamesNK 36892bf
Add integration test
JamesNK 7f9a1c5
Fix build
JamesNK ad59352
Fix build
JamesNK 4d2a3c0
Fix build
JamesNK File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/Servers/Kestrel/test/Interop.FunctionalTests/Http2/Http2RequestTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Net; | ||
using System.Net.Http; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Server.Kestrel.Core; | ||
using Microsoft.AspNetCore.Testing; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Interop.FunctionalTests.Http2; | ||
|
||
public class Http2RequestTests : LoggedTest | ||
{ | ||
[Fact] | ||
public async Task GET_NoTLS_Http11RequestToHttp2Endpoint_400Result() | ||
{ | ||
// Arrange | ||
var builder = CreateHostBuilder(c => Task.CompletedTask, protocol: HttpProtocols.Http2, plaintext: true); | ||
|
||
using (var host = builder.Build()) | ||
using (var client = HttpHelpers.CreateClient()) | ||
{ | ||
await host.StartAsync().DefaultTimeout(); | ||
|
||
var request = new HttpRequestMessage(HttpMethod.Get, $"http://127.0.0.1:{host.GetPort()}/"); | ||
request.Version = HttpVersion.Version11; | ||
request.VersionPolicy = HttpVersionPolicy.RequestVersionExact; | ||
|
||
// Act | ||
var responseMessage = await client.SendAsync(request, CancellationToken.None).DefaultTimeout(); | ||
|
||
// Assert | ||
Assert.Equal(HttpStatusCode.BadRequest, responseMessage.StatusCode); | ||
Assert.Equal("An HTTP/1.x request was sent to an HTTP/2 only endpoint.", await responseMessage.Content.ReadAsStringAsync()); | ||
} | ||
} | ||
|
||
private IHostBuilder CreateHostBuilder(RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action<KestrelServerOptions> configureKestrel = null, bool? plaintext = null) | ||
{ | ||
return HttpHelpers.CreateHostBuilder(AddTestLogging, requestDelegate, protocol, configureKestrel, plaintext); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: It's not super obvious from the name that
ParseHttp1x
returnstrue
when theMaxRequestLineSize
is exceeded before an\r
could be found. MaybeParseHttp1x
should just update theReadPrefaceState
or return its own tri-state enum.