Skip to content
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

[release/7.0] Fix Settings_MaxHeaderListSize_Server #46251

Closed
wants to merge 2 commits into from
Closed
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 @@ -1353,26 +1353,27 @@ public async Task Settings_MaxHeaderListSize_Server(string scheme)
{
ConfigureKestrel(webHostBuilder, scheme);
webHostBuilder.ConfigureServices(AddTestLogging)
.Configure(app => app.Run(context => throw new NotImplementedException()));
.Configure(app => app.Run(context => context.Response.WriteAsync("Hello World")));
});
using var host = await hostBuilder.StartAsync().DefaultTimeout();

var url = host.MakeUrl(scheme);

using var client = CreateClient();
// There's no point in waiting for the settings to sync, the client doesn't check the header list size setting.
// https://github.com/dotnet/runtime/blob/48a78bfa13e9c710851690621fc2c0fe1637802c/src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/Http2Connection.cs#L467-L494
// Send an initial request to ensure the settings get synced before the real test.
var responseBody = await client.GetStringAsync(url).DefaultTimeout();
Assert.Equal("Hello World", responseBody);

var request = CreateRequestMessage(HttpMethod.Get, url, content: null);
// The default size limit is 32kb.
for (var i = 0; i < 33; i++)
{
request.Headers.Add("header" + i, oneKbString + i);
}
var response = await client.SendAsync(request).DefaultTimeout();
await host.StopAsync().DefaultTimeout();
var ex = await Assert.ThrowsAsync<HttpRequestException>(() => client.SendAsync(request).DefaultTimeout());
Assert.Equal("The HTTP request headers length exceeded the server limit of 32768 bytes.", ex.Message);

Assert.Equal(HttpStatusCode.RequestHeaderFieldsTooLarge, response.StatusCode);
await host.StopAsync().DefaultTimeout();
}

[Theory]
Expand Down