2

My machine/ project details:

  1. Windows version is 10 Enterprise 1903 (OS build 18362.295)
  2. 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?

AzureMinotaur
  • 646
  • 2
  • 9
  • 22
  • Perhaps this is reverse process to disabling? https://stackoverflow.com/questions/31718533/disabling-http-2-spdy-in-http-sys-and-iis-in-windows-10 – orhtej2 Aug 27 '19 at 18:01
  • Does it work using HTTPS? I'm not sure http.sys can even do http/2 without TLS application layer protocol negotiation (ALPN) involved upgrading the request to 2.0 – Martin Ullrich Aug 27 '19 at 18:07
  • Thanks Martin, but trying this on HTTPS on my deployed service (same code) running on Windows server 2019 (2016 is required for http2) also returns the same result, so I think something else is missing – AzureMinotaur Aug 27 '19 at 18:16

0 Answers0