-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP/2 support #2125
Comments
Thanks for adding this, we'll eventually need to support HTTP/2. I'm not sure how it works, though. Will it integrate automagically with the current server? Because in Ilya Grigorik's implementation it doesn't look like it integrates with Rack. There's also this long thread which supports my guessing. And this Go talk which says that if you are using HTTPS and Go 1.6 you are using HTTP/2, so I guess it should be transparent. Maybe @igrigorik could chime in and at least let us know if the current client/server implementation is easily upgradable to HTTP/2? 😁 |
@asterite you can definitely abstract h2 behind the same API. That said, I do think you want to think carefully about the API to enable developers take advantage of h2: persistent connections, multiplexing, server push, etc. "Rack API", at least as it was defined for http/1.1, doesn't do a good job of this. FWIW, check out the demo client/server examples in the ruby gem: |
@igrigorik Thank you for replying, I'll take a look at the examples and see if I can port something to Crystal. |
@asterite recently changed HTTP::Server from a Rack-like interface (get a request, return a response) to instead pass a Context object with the Request and Response objects that middlewares will change, each context being evaluated in its own coroutine. I have a feeling that HTTP::Server could handle the HTTP/2 protocol, creating a Context object for each incoming Streams, using an intermediate IO to write to the Stream instead of the Socket —like deflate middleware currently does. The Context object could have additional methods for server push (among other HTTP/2 features), and either raise or silently skip when HTTP/2 isn't supported by the client. Hopefully this wouldn't affect the current middleware API but enhance it. |
An initial implementation is available: https://github.com/ysbaddaden/http2 If someone could point me to great HTTP2 compliance test suites, that would be very much appreciated. The client part is untested. It should be capable to use HTTP2::Connection, but it may require some tweaks. It's integration into The server part is almost complete, except for flow control (required) and applying priorities to send frames (nice to have). It's capable to talk with nghttp (with or without TLS) and browsers (ie. Firefox and Chrome, TLS only) and it supports server-push. Now we should start planning to integrate this into
|
@ysbaddaden take a look at https://github.com/summerwind/h2spec |
Thank you @igrigorik! I was able to reduce a bunch of corner cases in the protocol, down to 4 failures, most related to the unimplemented flow-control. |
Hey @ysbaddaden i remember you implementing HTTP/2 for Crystal. What's the status on that 😄 |
I too am very interested in the speed improvements that HTTP2 offers. I didn't know it had such wide support. @ysbaddaden should the work you're doing for http2 be moved into a crystal branch? I wouldn't mind writing a bunch of specs for it. |
Up. |
@DebugReport not that we are aware of. @samueleaton, if you are interested in contributing, I'd advise to do so in @ysbaddaden's repo, and as it's finished and tested, we can then include it into the stdlib. |
As far as I can tell @ysbaddaden's http2 shard is feature-complete and passes all h2spec tests. Awesome work. It doesn't look like there are any plans for integrating it back into Crystal though. I was planning on using it in my own project, a shard is fine, but I think it'd be nice to have in the std lib. I don't think http2 is going away. |
Hello @asterite, @bcardiff, @ysbaddaden, @waj and other core-team members, Would like to bring to your attention this issue, hoping if possible to introduce the changes required to support HTTP/2 into the stdlib. Not necessarily suggesting introduce HTTP/2 itself to the stdlib, but perhaps tweak Given that we are still in pre-1.0, perhaps is a good time to do some final breaking changes to the related API in preparation for that. HTTP/2 support will also open the door to gRPC, which can increase interoperability of Crystal for certain teams and projects. Also worth to mention HTTP/3 is around the corner 😉 Thank you for your hard and continuous work both Crystal core and other contributors, every new release gets better and better and you can feel how much sweat and hard work has been pour into it. Thank you! ❤️ ❤️ ❤️ Cheers. |
I think that |
Regarding HTTP (Client/Server) we wanted a way to decouple the protocol implementation from the socket tls wrapper. That will allow simple http over unix socket and other use cases where a simple http api is needed. (And would actually remove the need for the |
As a side note about WebSockets working with HTTP/2, I'm dropping these articles here, for those who are interested : https://hpbn.co/websocket/#websocket-multiplexing-and-head-of-line-blocking And the related RFC : |
Another take at Crystal HTTP2 implementation https://github.com/azutoolkit/duo |
I suppose at this point HTTP/2 support isn't that useful compared to HTTP/3 (which is basically the same, just based on QUIC instead of TCP). |
Recently Ilya Grigorik released a pure-Ruby implementation of HTTP/2: https://github.com/igrigorik/http-2 that decouples the transport from the HTTP/2 processing. |
@luislavena that gem has been around since 2013 with the last release in 2021 before this recent flurry of activity that seems to be led by AWS (https://github.com/mullermp) EDIT: Looks like There is also https://github.com/socketry/protocol-http2 by Samuel Williams |
I would say that it is just as useful, as it's possible that some clients/servers could support HTTP/2, but not HTTP/3. We should be going for all options that developers may be using. In any case, is anyone working on a PR yet? If not, I may tackle this myself over the summer. |
You're right. I didn't realize at the time I wrote this, that there are still good reasons for HTTP/2. I'm not aware of anyone working on this. Your help would be appreciated 👍 |
I had a conversation the other day about how I wish I had the background knowledge & time to take this on. A lot of tooling in the K8s/cluster orchestration space is based on HTTP2, and support for that stack in the core library would make crystal a much easier sell in the cloud ops space. If somebody else wants to take point, I'd be happy to try and pitch in! I definitely don't have the right background to lead the effort, nor do I currently have the time to skill-up and read the relevant RFCs & existing implementations. |
Another thought about this. When making requests with My first thought for a solution includes an enum for versions, and a constant that points to the newest version (Yes, I'm thinking forward compatibility). |
This is a feature request, tag it as you will. Since the specs have been clearly defined and do not appear to waver, I feel HTTP/2 should be supported in addition to HTTP/1.x.
Resources:
The text was updated successfully, but these errors were encountered: