From af713013d8e449d129767c688e16aee367968c93 Mon Sep 17 00:00:00 2001 From: Stephen Toub Date: Tue, 29 Sep 2020 10:30:19 -0400 Subject: [PATCH] Add test to validate HttpResponseMessage.RequestMessage --- .../HttpClientHandlerTest.Headers.cs | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs index 3eb14d17e9237..7ec1c22cf56bf 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs @@ -22,6 +22,29 @@ public HttpClientHandlerTest_Headers(ITestOutputHelper output) : base(output) { private sealed class DerivedHttpHeaders : HttpHeaders { } + [Fact] + public async Task SendAsync_RequestWithSimpleHeader_ResponseReferencesUnmodifiedRequestHeaders() + { + const string HeaderKey = "some-header-123", HeaderValue = "this is the expected header value"; + + await LoopbackServerFactory.CreateClientAndServerAsync(async uri => + { + using HttpClient client = CreateHttpClient(); + + var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri) { Version = UseVersion }; + requestMessage.Headers.TryAddWithoutValidation(HeaderKey, HeaderValue); + + using HttpResponseMessage response = await client.SendAsync(TestAsync, requestMessage); + Assert.Same(requestMessage, response.RequestMessage); + Assert.Equal(HeaderValue, requestMessage.Headers.GetValues(HeaderKey).First()); + }, + async server => + { + HttpRequestData requestData = await server.HandleRequestAsync(HttpStatusCode.OK); + Assert.Equal(HeaderValue, requestData.GetSingleHeaderValue(HeaderKey)); + }); + } + [Fact] public async Task SendAsync_UserAgent_CorrectlyWritten() {