-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Fix for issue #387 websocket proxy not work in node.js version 0.10.0 #402
Conversation
The headers in the 'handshake' event were not written to the socket, the client received data but not the headers.
thank you @pkarc! just lost 5 hours on this one. works for us. +1 |
@pkarc Thanks for this. Can you confirm the fix is backwards compatible with node@0.8.x? |
Tested on v0.7.0, v0.8.0, v0.8.2 and v0.8.6, and it works! |
This helps a bit (the headers aren't dropped like they are without this patch) but I'm still seeing weird results where the first data in the websocket gets written twice across the proxy. |
Specifically, it looks like the |
Yeah. Trace through the logic. In Then we actually read the headers over the network. By my reading of This in turn (with this patch) saves the headers into (BTW, if the initial block of data sent to socketOnData contained some bytes past the headers, this will be lost! This is the Finally, the proxied server sends the beginning of its body. This goes BOTH to Seems to me that the contents of |
This also is helping us a bit, but not quite a full fix--still getting weird behavior. Haven't quite dived down into the details as much as @glasser, but I can second that this is not quite a full fix. |
(Or, well, this whole thing probably should be rewritten to use Node 0.10-style |
Because of streams2, |
A third on this being insufficient: This doesn't seem to work on node v0.8.7 w/SSL (not sure if SSL is significant to the problem.) Also in my application the server end (proxy target) begins sending data first, again, not sure if that matters. I see the 'ondata' event for the socket fire first and call the 'handshake' function but meanwhile the 'upgrade' event hasn't fired yet to populate the status code and the 101 response headers so they are null and still don't find their way back to the browser to complete the handshake. I should add my browser is Chrome 26. |
Anyone looking at this? Seems node 0.10.13V isn't compatible with node-http-proxy - websockets when proxied are dropped. |
+1 Any way we can help short of leading a rewrite (I don't know the code well enough). Works so great on 0.8.x and would love to be able to use node-http-proxy with 10. |
This diff looks terrible but it seems to work well for the current version of the WebSocket protocol. I haven't tested it with the older drafts. It probably doesn't work for them. I don't have time to test it for older implementations but I'm using it in my project without issue. |
Awesome, thanks @indexzero , @cronopio ! |
Intentionally not choosing 0.10.2, which has a websocket proxying Node 0.10 semi-fix which I found to sometimes corrupt data (on Node 0.10). See my analysis on http-party/node-http-proxy#402 I do not know whether or not the PR corrupts data on 0.8, but it isn't necessary there, so I'm going to hold off on taking that change until the promised future complete rewrite of http-proxy to use the new 0.10 streams API.
Intentionally not choosing 0.10.2, which has a websocket proxying Node 0.10 semi-fix which I found to sometimes corrupt data (on Node 0.10). See my analysis on http-party/node-http-proxy#402 I do not know whether or not the PR corrupts data on 0.8, but it isn't necessary there, so I'm going to hold off on taking that change until the promised future complete rewrite of http-proxy to use the new 0.10 streams API.
The headers in the 'handshake' event were not written to the socket, the client received data but not the headers.
#387