-
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Support Upgrade requests #12
Comments
Notice that the "finished" string is printed before "open" and the received message which should not be the case if working as expected. |
Just curious: what is the behavior for res? |
I added a handler for res. Both print finished before any other output. |
K. I wonder if isFinished is a Boolean or undefined at the moment on_finished is called. |
Ok, so far what I see is that when |
As far as I can tell so far, this is how Node.js works; it considers the HTTP request/response to be done before the socket is handed over to continue with WebSockets. This is probably technically true, because "finished" in the Node.js sense is that of the actual HTTP message on the socket, and the HTTP message completely finishes once the WebSockets handshake occurs (even though you can now continue to communicate over the raw TCP socket--which is no different than pipelined HTTP messages). Basically this is what I'm seeing:
Basically, I'm seeing this as the expected behavior, in so much as this library says when a HTTP request or HTTP response is finished, which both are complete before |
Gotcha. Thanks for looking into it. Will consider it correct behavior in terms of http req/res cycles. Would it be appropriate to add something to the readme about this? |
Absolutely. I'm still doing a bit more research on what Node.js is doing and stuff, but it sounds like this may turn out to be a documentation issue, does that sound right to you :)? I also wonder if it would be worth adding something to the lib for WebSockets (currently you would have to |
Depends on the goals of the lib. If the goals are to handle the basic request/response cycle, then yea documentation is all that is needed. If the goal is to support http requests in general, one could argue that once upgraded, the socket is not yet finished nor has it error'd. I am not even sure it is true to say the response has finished. Because of this "what do we do" uncertainty, I would lean more towards saying just document the behavior with upgrade requests and say the user is responsible for detection after upgrade. The counter argument to the above is that everyone will likely have to write the same socket close handler code if they want to support websockets so why not just do it in the lib that handles a general request/response lifecycle. I personally am ok with documentation since it is really just a matter of knowing not to over-use the lib. |
(as a note to myself, this is the interesting part of core: https://github.com/joyent/node/blob/v0.10.26/lib/http.js#L1970-L1991) |
I agree with all your points, which is also why I'm in agreement with what the solution is to be here :) From looking around in the core, it doesn't so far like it's going to be easy (assuming it's possible) to get the after HTTP-lifetime cycle included in the "finished" on this module. As far as the way Node.js core is organized, I would say that the current limitation is that this module only supports |
I went ahead and updated the topic for this issue now that I understand what is going on with the report :) |
It seems we should be able to detect this based on |
Currently the biggest debate in my head right now is this, if you can weigh in on your opinion:
|
I would say that it should be: "logical" and "both default" But I am also strongly tempted to say: "http message finished" since folks using websockets or other longer lived connections will more likely be attaching themselves to the events on the socket. Also, keeps this module simpler and focused on the request/response lifecycle of 98% usecase for users of this module. Only happened to me because of my rather esoteric use of this module in localtunnel-server. |
Yea. And I've been thinking about it more as well and I'm kinda leaning on the "local" one being the only--mainly because the Upgrade requests are already split apart from "normal" requests in the way of then being different events, and of course if you're going to use this module on something from the I've been playing around with the code and it doesn't seem like the change is really big at all--just lots more tests in the test suite, mainly :) |
Darn these tests, lol. |
what's the issue? does |
It's not an issue with bouncy or anything. This is a request to support Upgrade requests by not triggering the finished until the socket is closed, rather than when the HTTP message is finished (and in node.js, the Upgrade requests are never not finished). |
@jonathanong right, bouncy just handles them both in this single function. I could have made the example using the core http module upgrade event instead but wanted to show a case where a user might try to use this module but get confused without realizing websocket upgrade requests were not supported. |
Yep. I'm just writing the tests in core, but I agree that when combined with |
Ok, sorry for the long delay on this issue. I have read up a lot about this to figure out what would make the most sense. In the end, accounting for the actual behavior of |
And for the record, I have basically been debating between keeping the existing behavior and documenting, or using this behavior:
|
👍 |
Using on-finished on a request that is then upgraded causes it to erroneously detect that the request is finished.
Below is a minimal example which shows this failure:
Bouncy is used here since it handles both regular requests and upgrade requests. And engine.io has been hard pinned to use on the websocket transport (same as using raw websockets basically).
The text was updated successfully, but these errors were encountered: