My machine/ project details:
- Windows version is 10 Enterprise 1903 (OS build 18362.295)
- Dotnet core version is 2.2.106, target framework version is 4.6.2
This is how the server is setup in code:
IWebHost localWebHost = new WebHostBuilder()
.UseHttpSys()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseApplicationInsights(instrumentationKey)
.UseStartup<Startup>()
.UseUrls("http://+:8644")
.Build();
But calling with http version 2.0 still returns response with 1.1 (LinqPad script below):
async Task Main()
{
using (var httpClient = new HttpClient(new Http2CustomHandler()))
{
var stopwatch = new Stopwatch();
stopwatch.Restart();
var response = await httpClient.SendAsync(new HttpRequestMessage
{
Method = HttpMethod.Get,
// replacing uri with "https://www.google.com" returns http version 2.0
RequestUri = new Uri("http://localhost:8644/api/health", UriKind.Absolute)
});
response.RequestMessage.Version.Dump();
response.Version.Dump();
stopwatch.ElapsedMilliseconds.Dump();
}
}
public class Http2CustomHandler : WinHttpHandler
{
protected override System.Threading.Tasks.Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
{
request.Version = new Version("2.0");
return base.SendAsync(request, cancellationToken);
}
}
I get 2.0 from the response.RequestMessage.Version
but 1.1 from response.Version
. Replacing local uri with google's returns 2.0 in the response (so the code above is correct)
HttpSysOptions does not have any parameter related to http2 either. Anyone know what else I am missing?