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
WebSocket support? #3058
WebSocket support? #3058
Conversation
Thanks. I intended to spend yesterday working on Puma, then a Windows thing came up. From the Actions Windows Ruby 3.1 log:
It passes CI, but having Ruby and Puma compile with different OpenSSL versions is not something we want happening. This has nothing to do with Puma, it's all in the code setting up GitHub Actions for Ruby. Fine print: The MSYS2 system, which provides the build tools and packages used to build most Windows Rubies, updated their OpenSSL package from 1.1.1s to 3.0.7. |
Amazing work @dentarg! Thank you for doing this. |
@dentarg Thanks for working on this. Just added an Actions workflow that uses rack_conform to test Puma. Right now, it can 'silently' fail, not sure if that should be removed? @ioquatix This PR fixes Puma websocket support, and adds a workflow that uses the websockets branch of rack_conform to test Puma. Anyway to get a list of the tests? I assume at some point we'll switch to the main branch. Note that the workflow 'hacks' the gemfile as below,
|
I would also be okay with adding local test gem files to rack-conform if that makes it easier - can you not use the form It would be neat if we could figure out how to use https://github.com/ioquatix/bake-test-external to do this orchestration more easily because It would be awesome to encourage other servers to adopt |
@ioquatix Please allow the Window's guy some slack with sed. My original sed strings were terrible, updated to:
I think it will be a bit more stable. I'm ok with this, as we're running the CI as if it's from the rack-conform repo, and changing the 'Gemfile' before |
This looks good to me! |
Thanks. Please let us know when we can change to the main branch. Don't know about everyone else, but after seeing all the strange-ass things various (external) response classes do, I think it's a good idea for Puma to test with repos like rake-conform and turbo-rails... |
Okay, I will work on merging the websockets PR on rack-conform, if we can merge this one soon it will help. |
One reason I paused on this code is the status code handling. I believe any response with a status code < 200 is considered a 'no body/content' response. IANA's Hypertext Transfer Protocol (HTTP) Status Code Registry and MDN only show four codes in that range. But, here and there it's implied that servers/apps can/may define their own. Thoughts? This code does not handle undefined 100 'range' codes as 'no body' codes... |
As long as you're back in that repo, might it log the tests? It's not like there's hundreds/thousands of them... BTW, no hurry, and thanks for getting it up and running. Should be in the rack account, but maybe that's planned for later. And, any other servers can feel free to use the workflow in their CI... |
@jeremyevans what do you think about moving the rack-conform test suite to the rack org? |
I've argued this within the rack spec, since The current implementation assumes that a streaming body is a super-set of entity bodies, and thus you shouldn't prune the response body for 1xx responses with a streaming response body, and was implemented in rack/rack#1993 |
I think we should be more conservative when adding new repositories to the rack org. In hindsight, I don't think rack-test or rack-attack should have been moved to it. After looking at the rack-conform repository and dependencies, I'm not in favor of moving rack-conform to the rack org. In general, I don't think we should move external repositories into the rack org unless we have multiple rack committers willing to maintain them. |
Makes sense. But, as I've seen with Puma, web/app servers may be affected by small behavior changes in Rack, and they may not be testing for them. Some kind of conformance code might be helpful. Haven't really thought about it much... |
Marking as "waiting for changes" as it maybe needs a test or two in the Puma test suite. @dentarg do you feel up to that or want me and Greg to do it? Don't want you to sign up for more than you want to! 😄 |
Okay, so my read is, the bar for moving As it stands, it's fine where it is, but long term, eventually I have to assume I'm no longer going to be around (hopefully not for a long time). But when that happens, it makes sense that there is a way to continue maintaining the code if servers are using it as part of validating their conformance to the rack spec. |
JFYI, the additional workflow (using rack-conform) is creating a websocket connection, and also testing that the server (Puma) is correctly returning a 101 ('Switching Protocols') response and passing the IO to the app. I assume that some apps may hijack the connection and handle the 101 response themselves... |
@nateberkopec if you or @MSP-Greg can add the tests we need, that's fine with me! Currently I don't know when I have a chunk of time free for that |
I have merged the |
Re tests, see the last commit 'Create test_puma_server_partial_hijack.rb, pull 1 test from test_puma_server.rb'. It pulls one test from test_puma_server.rb. The two new tests fail when the commit is cherry picked to master. |
I just added three commits, one which reverts the first commit, which is the 101 fixes. The first original commit changed the definition of But, RFC 9110 15.2 clearly states "A 1xx response is terminated by the end of the header section; it cannot contain content or trailers." The last new commit "request.rb - properly handle 101 'Switching Protocols' responses" correctly handles the above cases. The new tests seem to be failing on TruffleRuby, possibly due to using syswrite & sysread. Not.sure. I hope to look at it sometime today. |
I'd like to introduce Essentially:
This also helps us in HTTP/2 which has a different "upgrade" mechanism (which doesn't use 101 status code). |
Added one more commit, fixes the TruffleRuby issue. Adding an All passed in the test workflow. I consider this finished, any thoughts? |
Okay, let me give it a review. w.r.t. my previous comment, detecting 101 status is good enough for now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Discuss in Rack? JFYI, I'm kind of meh about it, as, assuming most WebSocket is
I have yet to really take a 'deep dive' into HTTP/2 (or HTTP/3), so I'm speaking mostly about HTTP/1... |
Yep, we have a discussion for it: rack/rack#1946 Right now, you are expecting the response to include the |
I've just merged and released support for webrick (v1.8.0) bi-directional streaming, added support in rackup (v2.1.0), and tested this using the conformance test suite (fully passing now for webrick on Rack 3). Looking forward to merging and releasing this PR too!! By the way, I don't care much about webrick, but it's our lowest common denominator when it comes to rackup, so it makes sense it at least works correctly (perhaps performance is less of an issue/concern). I've added support for both I don't actually have a strong opinion about this, but it's useful not to have to special case HTTP v1 and v2 too much, given that the upgrade header should not be specified on an HTTP/2 response. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few minor clarifications and then I'm ✅
Looking good! |
Nice! |
Description
I've rebased @MSP-Greg's branch https://github.com/MSP-Greg/puma/tree/00-size-to-first-byte-ws
With these changes, Puma passes the Rack::Conform "Basic WebSocket connection test", see https://github.com/dentarg/rack-conform/actions/runs/3928289028/jobs/6715741130
Needs some tests
Close #3007
Your checklist for this pull request
[ci skip]
to the title of the PR.#issue
" to the PR description or my commit messages.