http-proxy doesn't proxy the latest websocket specifications
Problem
Howdy, A few days ago, we added FF6 and Chrome 14 websocket support to Socket.IO. But http-proxy doesn't seem to be able to proxy these upgrade events. If I run a plain Socket.IO 0.8.2 chat example it works fine in FF6 and latest chrome, but if I add node-http-proxy infront of it only the Draft 76 specification receives a upgrade event. After a bit digging I found out that https://github.com/nodejitsu/node-http-proxy/blob/master/lib/node-http-proxy.js#L862 doesn't get fired for the new websocket specifications (it does work for older websocket specifications like draft 76)
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Update node-http-proxy to Support Latest WebSocket Specifications
The current implementation of node-http-proxy does not handle the upgrade events for the latest WebSocket specifications, specifically those introduced after Draft 76. This is due to the lack of proper handling in the upgrade event logic, which only recognizes older drafts, leading to a failure in establishing WebSocket connections for newer browsers like FF6 and Chrome 14.
Awaiting Verification
Be the first to verify this fix
- 1
Clone the node-http-proxy Repository
Clone the node-http-proxy repository from GitHub to modify the source code for supporting the latest WebSocket specifications.
bashgit clone https://github.com/nodejitsu/node-http-proxy.git - 2
Modify Upgrade Event Handling
Edit the 'node-http-proxy.js' file to include handling for the latest WebSocket upgrade requests. Locate the section where the upgrade events are processed and add conditions to recognize the new WebSocket handshake headers.
javascript// Add this condition to handle new WebSocket specifications if (req.headers['sec-websocket-version'] && req.headers['sec-websocket-key']) { // Handle the upgrade logic for new WebSocket specs } - 3
Test the Modified Proxy
Run your modified version of node-http-proxy with a Socket.IO server to ensure that WebSocket connections can be established using the latest specifications. Use a test client in FF6 or Chrome 14 to verify functionality.
bashnode path/to/modified/node-http-proxy.js - 4
Deploy the Updated Proxy
Once testing is successful, deploy the modified node-http-proxy in your production environment. Ensure to monitor the logs for any unexpected behavior or errors.
bashnpm install path/to/modified/node-http-proxy
Validation
To confirm the fix worked, initiate a WebSocket connection from a client using the latest specifications and check the server logs for successful upgrade events. Additionally, verify that the WebSocket connection is established and messages can be sent and received without errors.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep