Skip to content

Commit

Permalink
Add test to validate HttpResponseMessage.RequestMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Oct 1, 2020
1 parent ee993b4 commit af71301
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit af71301

Please sign in to comment.