Set HttpResponseMessage.Version in TestServer (#16941)

This commit is contained in:
James Newton-King 2019-11-10 13:59:34 +13:00 committed by GitHub
parent dbba49cc25
commit 909f1d368f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 0 deletions

View File

@ -163,6 +163,7 @@ namespace Microsoft.AspNetCore.TestHost
response.StatusCode = (HttpStatusCode)httpContext.Response.StatusCode;
response.ReasonPhrase = httpContext.Features.Get<IHttpResponseFeature>().ReasonPhrase;
response.RequestMessage = request;
response.Version = request.Version;
response.Content = new StreamContent(httpContext.Response.Body);

View File

@ -823,5 +823,48 @@ namespace Microsoft.AspNetCore.TestHost
Assert.Same(value, capturedValue);
}
[Fact]
public async Task SendAsync_Default_Protocol11()
{
// Arrange
var expected = "GET Response";
RequestDelegate appDelegate = ctx =>
ctx.Response.WriteAsync(expected);
var builder = new WebHostBuilder().Configure(app => app.Run(appDelegate));
var server = new TestServer(builder);
var client = server.CreateClient();
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:12345");
// Act
var message = await client.SendAsync(request);
var actual = await message.Content.ReadAsStringAsync();
// Assert
Assert.Equal(expected, actual);
Assert.Equal(new Version(1, 1), message.Version);
}
[Fact]
public async Task SendAsync_ExplicitlySet_Protocol20()
{
// Arrange
var expected = "GET Response";
RequestDelegate appDelegate = ctx =>
ctx.Response.WriteAsync(expected);
var builder = new WebHostBuilder().Configure(app => app.Run(appDelegate));
var server = new TestServer(builder);
var client = server.CreateClient();
var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:12345");
request.Version = new Version(2, 0);
// Act
var message = await client.SendAsync(request);
var actual = await message.Content.ReadAsStringAsync();
// Assert
Assert.Equal(expected, actual);
Assert.Equal(new Version(2, 0), message.Version);
}
}
}