justcoding121 / titanium-web-proxy

A cross-platform asynchronous HTTP(S) proxy server in C#.
MIT License
1.93k stars 612 forks source link

HTTP/2 support #300

Open justcoding121 opened 7 years ago

justcoding121 commented 7 years ago

Now that we are set with ALPN support, shouldn't have any roadblock that would impede HTTP/2 support. The good news is that the hacked ALPN support mentioned in issue #293 should also work cross platform since we are not doing any kind of reflection or native calls. I haven't read the spec complete, but few open source implementations of both server and client seem to be available. So we can perhaps reuse them. Some links below.

  1. http://httpwg.org/specs/rfc7540.html (Spec)
  2. https://github.com/Matthias247/http2dotnet (which claim to have a complete implementation of server & client in C#) and has MIT license.

I am not going to work on this in immediate future. But if anybody is interested this is up for grab. Doesn't necessarily need to implement a fully functional PR, bugs are expected and PRs with phase by phase progressions are welcome. Whatever work on this we will be doing a beta first. We should try to isolate the HTTP/2 handlers from current Request/Response handlers since it a totally different protocol from whatever I read. There are different scenarios we would probably need to handle. These scenarios should work for both SSL and non-SSL connections. When SSL is used HTTP/2 can be negotiated via ALPN, while for non-SSL connections HTTP/2 is done by upgrade headers mentioned in spec.

  1. Client to proxy HTTP 1.1 => Proxy to server HTTP/2
  2. Client to proxy HTTP 1.1 or below => Proxy to Server HTTP 1.1 or below (which is already implemented)
  3. Client to proxy HTTP/2 => Proxy to server HTTP 1.1
  4. Client to proxy HTTP/2 => Proxy to server HTTP/2

For now the 4th option would be a good start.

justcoding121 commented 7 years ago

As mentioned in below issue for StreamExtended we have to wait for official ALPN support, our hack won't work due to message integrity checks happen at the end of Ssl negotiation.

https://github.com/justcoding121/StreamExtended/issues/1

honfika commented 6 years ago

ALPN support was added to .NET Core, it will be included in version 2.1. Roadmap says that it will be released in Q2. https://github.com/dotnet/corefx/pull/24389

So we can support it (a half year later), but it needs a new targetframework. Currently we have net45, netstandard2 and a new netcoreapp2.1 is needed.

justcoding121 commented 6 years ago

Hmm. I think we will have to set it up then. I hate these evolving naming conventions though :-)

justcoding121 commented 6 years ago

@honfika I noted that you made some setup to support HTTP 2.0. So I assumed you may be working on it in future. Feel free to remove assignee.

honfika commented 5 years ago

4th option implemented in readonly mode (not able to modify neither the header nor the body)

HTTP/2 support should be enabled with the ProxyServer(instance).EnableHttp2 flag.

I plan to add the "edit mode" in the near future, too. (option 4th)

ByronAP commented 5 years ago

any update on this?

honfika commented 5 years ago

Partially it was impemented, but it work only with dotnet core 2.1+

What feature do you need exactly?

ByronAP commented 5 years ago

not a need but would be nice to support transparent (Client to proxy HTTP/2 => Proxy to server HTTP/2)

ByronAP commented 5 years ago

seems to me most people are using 2.1+ now as well so compatibility should not be too big of an issue

honfika commented 5 years ago

Just simply forwarding the traffic without modifying that?

ByronAP commented 5 years ago

yeah the issue appears to be upgrade h2c support and or cipher negotiation

honfika commented 5 years ago

As far as I understood h2c is just an unencrypted http/2. Do you really need http/2 without tls?