From f37a7509121e1ddb8e517a2e255b7c3bf3780174 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Fri, 6 Mar 2020 07:42:26 +1300 Subject: [PATCH] Add functional test for header string reuse in HTTP/1.1 (#19588) --- .../InMemory.FunctionalTests/RequestTests.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestTests.cs b/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestTests.cs index 2e63e458ac..dafbd6eca7 100644 --- a/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestTests.cs +++ b/src/Servers/Kestrel/test/InMemory.FunctionalTests/RequestTests.cs @@ -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() {