Runtime: Adding HTTP 2.0 support to HttpClient

Created on 7 Dec 2015  路  14Comments  路  Source: dotnet/runtime

It appears as though UWP has a new HttpClient in the Windows.Web.Http namespace which has HTTP 2.0 support: https://msdn.microsoft.com/en-us/library/windows/apps/mt187345.aspx

Is porting this work to the coreclr HttpClient in the roadmap?

area-System.Net enhancement

Most helpful comment

First, discussions on closed issues such as this are not guaranteed to get a response from anyone since the issue is closed.

Second, you can use WinHttpHandler on .NET Framework. You must only use the SendAsync() methods from HttpClient. Those are the only ones that allow you to pass in an HttpRequestMessage. Other methods, use a default HttpRequestMessage that uses Version(1,1) only.

You have to set the .Version field in HttpRequestMessage to 2.0 as indicated. You have to use a current version of Windows 10.

Other than that, HTTP/2 protocol should work against an HTTP/2 server. You'll know if works when you get an HttpResponseMessage with Version field set to 2.0.

All 14 comments

cc; @SidharthNabar

@callumelgrant - There are a few aspects to this:

  1. The HttpClient type in Windows.Web.Http is not "new" in UWP. It has existed since Windows 8.1 and is a WinRT type, completely different from the System.Net.Http.HttpClient type of .NET. However, the design for both is similar. For more info on this - see this blog post https://blogs.windows.com/buildingapps/2015/11/23/demystifying-httpclient-apis-in-the-universal-windows-platform/
  2. The .NET API System.Net.Http.HttpClient also supports HTTP/2 in UWP apps. In terms of API surface, you can set HttpRequestMessage.Version to HttpVersion.Http20, and the underlying stack will then use HTTP/2.
  3. Whether or not System.Net.Http supports HTTP/2 on a specific platform will depend on the underlying implementation on that platform (since in terms of API surface, we already support it). For .NET platforms, the current status is as follows:
    (a) .NET Core for UWP - Yes
    (b) .NET Core on Unix - Yes (See issue dotnet/corefx#4756),
    (c) .NET Core for ASP.NET 5 on Windows - Not yet (this is on our roadmap)
    (d) .NET Framework 4.6. - Not yet (this is on our roadmap)

.NET Core for ASP.NET 5 on Windows - Not yet (this is on our roadmap)

:+1: Awesome!

@SidharthNabar: you've mentioned that http/2 support for _.NET Core for ASP.NET 5_ and _.NET Framework 4.6_ is already on your roadmap. Is this roadmap publicly available somewhere? Do you have an approximate timeline for that?

cc: @himadrisarkar @CIPop

HTTP/2.0 support will be added post RTM for .NET Core 1.0 to a future iteration of the System.Net.Http package. And that package can also be installed for .NET Framework 4.6 applications.

The NuGet package will be required to get HTTP/2.0 functionality. We do not plan to add HTTP/2.0 directly to the .NET Framework 4.6.* runtime.

HTTP/2.0 support will be added post RTM for .NET Core 1.0 to a future iteration of the System.Net.Http package.

Cool. Do you know if this will support server-push aspects of the spec? It would be nice if this (https://github.com/Redth/HttpTwo) incomplete implementation could be replaced.

Any updates?

HTTP/2.0 support will be added post RTM for .NET Core 1.0 to a future iteration of the System.Net.Http package.

Cool. Do you know if this will support server-push aspects of the spec? It would be nice if this (https://github.com/Redth/HttpTwo) incomplete implementation could be replaced.

This was completed in PR dotnet/corefx#10948.

In terms of full support server-push aspects of the spec....no, on Windows System.Net.Http using the OS native component WinHTTP for the HTTP stack. WinHTTP does not fully support server-push aspects.

Thanks for the quick reply, is it on a roadmap anywhere or can you recommend alternatives on Windows?

Thanks for the quick reply, is it on a roadmap anywhere or can you recommend alternatives on Windows?

In term of full support for server-push aspects of the spec, I have no information yet on timelines for that. That requires getting information from the WinHTTP team about the feature plans for Windows 10 updates. I will forward this inquiry to the team and see if I can get an answer.

In terms of alternative client HTTP stacks on Windows that support HTTP/2.0 protocol including full support for server-push aspects....I don't have any information on that.

I am trying to call a http/2 api using HttpClient in a project targeting 4.6.2 and can't find HTTP 2.0 support. System.Net.HttpVersion has only Version10 and Version11. Just want to confirm if I Http/2 is supported for Httpclient in Framework 4.6.2 ?

Just want to confirm if I Http/2 is supported for Httpclient in Framework 4.6.2 ?

HTTP/2 protocol is NOT supported on any version of .NET Framework binaries.

To use HTTP/2 protocol support, you must use .NET Core. You must also use a supported version of Windows 10. And you need to manually specify HttpRequestMessage.Version = new Version(2,0);

You can also use the separate System.Net.Http.WinHttpHandler package which provides an alternate handler for HttpClient. You need to create that WinHttpHandler and pass it into the constructor of HttpClient. This WinHttpHandler package is supported on both .NET Core .NET Framework.

Thanks for the quick reply. In second option WinHttpHandler. Do I just need to change the version to 2.0 or it would require any other changes?

First, discussions on closed issues such as this are not guaranteed to get a response from anyone since the issue is closed.

Second, you can use WinHttpHandler on .NET Framework. You must only use the SendAsync() methods from HttpClient. Those are the only ones that allow you to pass in an HttpRequestMessage. Other methods, use a default HttpRequestMessage that uses Version(1,1) only.

You have to set the .Version field in HttpRequestMessage to 2.0 as indicated. You have to use a current version of Windows 10.

Other than that, HTTP/2 protocol should work against an HTTP/2 server. You'll know if works when you get an HttpResponseMessage with Version field set to 2.0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nalywa picture nalywa  路  3Comments

aggieben picture aggieben  路  3Comments

bencz picture bencz  路  3Comments

omariom picture omariom  路  3Comments

matty-hall picture matty-hall  路  3Comments