Is it possible to use HTTP2 with HTTPListener
Asked Answered
P

1

9

Is it possible to use http2 features with HTTPListeners yet? I didn't hear anything about it but i heard that the new releases of the IIS / asp.net stack support it so i was hoping HTTPListener would be ugpraded too or an alternative would be provided.

If not what would be the best option to support http2, working with raw sockets or is it possible at all to extend httplistener?

Edit : to clarify i'm not just looking for a solution that "reports" http2 but one that enables me to actually use http2 new features such as pushing content, my use case is i have a custom CMS (self written) server that is extremely low latency (replies near instantly to all requests) and the only thing left to optimise is being able to push content AND being able to multiplex as currently the only speedup i can hope for is avoiding the latency from so many rountrips

Parterre answered 8/5, 2015 at 23:49 Comment(0)
D
10

HttpListener is a managed "client" for the Windows kernel module http.sys (similar to how IIS is also a client for it). This version of this module which handles HTTP/2 appears to be only available in Win10 / IE. If you are running on Win10 and an HTTP/2 connection is made, it will likely look the same to HttpListener, since the interface to http.sys driver abstracts the protocol for clients of HttpListener. If anything is different, it would be the HttpListenerResponse.ProtocolVersion showing HTTP/2.

Looking at the source of HttpListener, it seems like the interface to http.sys is blob-oriented, just subscribing to requests and getting the request data in one big blob. This blob forms the basis of the managed HttpListenerContext class, which has the request and response data exposed as properties. The HttpListenerResponse sends the response via http.sys by breaking the data into headers and data chunks which it exposes via the OutputStream property. If multi-streams would be supported, this public API would need to change. It is certainly not currently supported, and my guess is that they won't change this API, and if HTTP/2 will be supported by HttpListener either it will completely abstract HTTP/2 or provide some kind of WriteAsync method to multiplex at this higher level. It sounds like you want to write directly against http.sys to take advantage of lower level features of the protocol.

Diazomethane answered 11/5, 2015 at 2:35 Comment(9)
But i'm looking at using http2 features so unless there is explicit feature support on the .net side i don't think i can do that (like pushing additional data that wasn't requested to the client), or am i missunderstanding something?Parterre
The entire HTTP conversation between the client and the server is handled by http.sys. HttpListener only gets the request data from http.sys and sends responses back to the client through it. The public interface of HttpListener doesn't have to change once http.sys supports HTTP/2.Diazomethane
It does if the new features are to be exposed, for example pushing content, i don't see how that could be exposed in the current interface, or if you think it can could you write a sample?Parterre
As I noted above in the edit, it is currently not possible, since the source shows a single response handle to http.sys. It might be possible in the future, but I'd suspect it will still be very high level.Diazomethane
Then this leaves us with the second option in my question "If not what would be the best option to support http2, working with raw sockets or is it possible at all to extend httplistener?". Any ideas on that? I'm assuming writing my own full httplistener replacement with http2 support would be nontrivial?Parterre
You could go the route of implementing it in sockets - sockets are low enough level where it would be possible, however as you note, it's not going to be easy. Also since http.sys works at the kernel level and system wide, it gives the best performance. Short of writing your own kernel driver, you're always going to be at a performance disadvantage. Another approach would be to write directly against the Win10 http.sys driver similar to what HttpListener does. However, it doesn't look documented for now...Diazomethane
Hmm actually i Wonder if httphandler is in the .net core part that was released as open source, maybe a good middle ground would be to start from that implementation instead of re wrapping http.sys from scratch and then modifying it for http2 supportParterre
Yea, could be a good start to at least give you a better idea of where to go. Reference Source here: referencesource.microsoft.com/#System/net/System/Net/…Diazomethane
Can't award Bounty for 21 more hours but will do when timer expires, for reference it could be good to add the diferent solutions to your answer (httpsys native, using .net core, waiting for httplistener to be improved etc)Parterre

© 2022 - 2024 — McMap. All rights reserved.