Add functional test for header string reuse in HTTP/1.1 (#19588)

This commit is contained in:
James Newton-King 2020-03-06 07:42:26 +13:00 committed by GitHub
parent 487a0f6a5d
commit f37a750912
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 55 additions and 0 deletions

View File

@ -1684,6 +1684,61 @@ namespace Microsoft.AspNetCore.Server.Kestrel.InMemory.FunctionalTests
}
}
[Fact]
public async Task ReuseRequestHeaderStrings()
{
var testContext = new TestServiceContext(LoggerFactory);
string customHeaderValue = null;
string contentTypeHeaderValue = null;
await using (var server = new TestServer(context =>
{
customHeaderValue = context.Request.Headers["X-CustomHeader"];
contentTypeHeaderValue = context.Request.ContentType;
return Task.CompletedTask;
}, testContext))
{
using (var connection = server.CreateConnection())
{
// First request
await connection.Send(
"GET / HTTP/1.1",
"Host:",
"Content-Type: application/test",
"X-CustomHeader: customvalue",
"",
"");
await connection.Receive(
"HTTP/1.1 200 OK",
$"Date: {testContext.DateHeaderValue}",
"Content-Length: 0",
"",
"");
var initialCustomHeaderValue = customHeaderValue;
var initialContentTypeValue = contentTypeHeaderValue;
// Second request
await connection.Send(
"GET / HTTP/1.1",
"Host:",
"Content-Type: application/test",
"X-CustomHeader: customvalue",
"",
"");
await connection.Receive(
"HTTP/1.1 200 OK",
$"Date: {testContext.DateHeaderValue}",
"Content-Length: 0",
"",
"");
Assert.NotSame(initialCustomHeaderValue, customHeaderValue);
Assert.Same(initialContentTypeValue, contentTypeHeaderValue);
}
}
}
[Fact]
public async Task Latin1HeaderValueAcceptedWhenLatin1OptionIsConfigured()
{