-
Notifications
You must be signed in to change notification settings - Fork 2k
http-proxy doesn't proxy the latest websocket specifications #97
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
Comments
@3rd-Eden. The The new version of the websocket draft is on our list of priorities, but we probably won't implement it until the 0.6.x timeframe. |
@indexzero I don't know if it's a core bug, I don't know enough of the node-http-proxy module to debug it further. I might have missed something obvious. |
@3rd-Eden I'll try to take a stab at it if I get some cycles this week. NodeConf SummerCamp is next week so I'm kinda strapped for time. |
+1 This issue makes me T_T Thanks guys! |
Any news on this? I'd love to use node-http-proxy, but I need WebSocket (including newer drafts) support... |
No. This is a difficult problem. |
@3rd-Eden I can confirm this. I can also confirm that Firefox 6 is not working either apparently. I did some digging and here's what I'm seeing Firefox 7{ host: 'localhost',
port: 3000,
method: 'GET',
path: '/socket.io/1/websocket/1994801303780560091',
headers:
{ host: 'localhost:8000',
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:6.0.2) Gecko/20100101 Firefox/6.0.2',
accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'accept-language': 'en-us,en;q=0.5',
'accept-encoding': 'gzip, deflate',
'accept-charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.7',
connection: 'keep-alive, Upgrade',
'sec-websocket-version': '7',
'sec-websocket-origin': 'http://localhost:8000',
'sec-websocket-key': 'i6qqGU2E/s16IHmVLxhXEg==',
pragma: 'no-cache',
'cache-control': 'no-cache',
upgrade: 'websocket' } } Chrome 13{ host: 'localhost',
port: 3000,
method: 'GET',
path: '/socket.io/1/websocket/13704292091528906386',
headers:
{ upgrade: 'WebSocket',
connection: 'Upgrade',
host: 'localhost:8000',
origin: 'http://localhost:8000',
'sec-websocket-key1': '2 [ 1O09 k^ hr 0u.0123 0',
'sec-websocket-key2': '31 0g[| 38.5DyvA6 9 4yqG 0U',
cookie: '__utma=1.484068460.1314426697.1314426697.1314426697.1; __utmz=1.1314426697.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); _chartbeat2=xjfrmfu3529rbg7z' } } |
Clearly this isn't working in Firefox 6 because Firefox 6 implements WebSockets draft-07 (source: http://en.wikipedia.org/wiki/WebSocket) |
@3rd-Eden Did further investigation here. This may be a bug in node.js core (or more specifically the response parsing in http-parser so I'm going to attempt to summon @ry. I can confirm deep in the tendrils of node (https://github.com/joyent/node/blob/v0.4.11/lib/http.js#L1230-1265), the I'm no expert of the HttpParser used by node.js here, but it seems like the "Request" mode (working): https://github.com/joyent/node/blob/v0.4.11/lib/http.js#L1020 I'm building |
But the odd thing is that If we attach socket.io to a normal HTTP server it does work. So it's not a fundamental flaw on the node core, it might just be related to http client On 10 sep. 2011, at 12:08, Charlie Robbins wrote:
|
@3rd-Eden @ry I can confirm that this still isn't working in Firefox 6 and Chrome 14 upon upgrading to I would like to make note for @mikeal that However, the |
The http2 compatible of |
Exactly. When you attach socket.io to a normal HTTP server the I'm not sure if these bugs are in the https://github.com/Worlize/WebSocket-Node/blob/master/lib/WebSocketClient.js#L149-150 |
So if http-proxy starts using the old interface this would be resolved i guess? On 10 sep. 2011, at 13:16, Charlie Robbins wrote:
|
Thats not a viable solution |
@3rd-Eden Wanted to give more info on my last comment. It was like 8am here; so I was pretty spent after pushing out From what I can see in |
I spent some time reading the
where as in Chrome 13 and older versions of the spec the header is:
Based on our first pass it seems like the parser enters the Not sure how simple a fix this is, but @bmeck will be putting together a low-level parser repro next week. |
please provide an example request that youve seen in the wild with |
@ry Firefox 7 Websocket Requests. Seems to be consistent across Firefox 6 (draft7), Firefox 7 (draft10) and (reportedly) Chrome 14 (draft10). More info in this comment: #97 (comment) |
Best way to repoduce this is in the wild is to open the simple chat example for socket.io that @3rd-Eden suggested in Firefox 6 or 7. I'm using a different socket.io sample app: http://github.com/fat/space-tweet. To run this just [Update config.json with valid Twitter credentials]
npm install
node server.js Then you can throw a proxy server in front of it require('http-proxy').createServer(3000, 'localhost').listen(8000); I found an interesting discussion on the ietf mailing list about a bug in the draft11 spec which confirms that comma-separated
|
Well there seems to be 2 seperate issues then. Because Chrome beta and Chromium are sending the following headers:
And they are not answered correctly by the proxy either. So it seems to me that the
Isn't the only reason why node-http-proxy fails to proxy requests. |
Interesting. Again, in this case as you pointed out @3rd-Eden it is just that the |
I wonder where is (Key3):00:00:00:00:00:00:00:00 coming from, I am trying to implement draft-ietf-hybi-thewebsocketprotocol-15 in jwebsocket.org. But keep getting disconnected. I am using chrome 14.0.835.163 |
I think I might know what causes this bug. Websockets are messed up a bit in Chrome 14 (I remember that this was a real issue during node knockout), and Firefox's support for them is limited. As you can see, neither browser supports binary frames, while socket.io seems to be using it. In fact, I was able to run socket.io chat demo with node-http-proxy and Chrome 15.0.874.15 dev (and yes, it was using Websockets transport - verified by For me, it seems that the source of problem is that browsers are trying to use newest hybi specification, but don't actually implement it fully. However, please note that I may be terribly wrong and YMMV. |
After some further investigation with @AvianFlu: Parser doesn't seem to be a problem. It detects upgrades just fine (and fires this callback). Proxy receives http requests like:
But fails to pass them further. This callback doesn't get executed at all. Comparison between direct and proxied request - forwarded requests have their headers all in lower case. No forwarded request has an I'll investigate it further, but it's 4 AM and it's basically a brain dump. |
After some further further investigation: In this line we append a message to a queue and we hope that eventually (when socket is assigned) it'll be send to a server. In fact, socket gets assigned in the very first Weirdest thing is: after some time In fact, I can force this flush by inserting
|
The request gets stuck, as @mmalecki said, and then, since there's no error status, eventually https://github.com/joyent/node/blob/v0.4.12/lib/http.js#L1284-1293 is reached and the "socket hang up" message is received. The real key to fixing this lies in figuring out how to make it past https://github.com/joyent/node/blob/v0.4.12/lib/http.js#L753 to the socket.write() call at the end of that method. |
Do you guys have a simple test case yet? Put one together send it to me and I'll just fix it. You guys are thinking too hard. A simple test case would be: tcpdump the req/res in question, set up a http server, have a tcp client connect to it - send the request as you got it from the tcpdump - assert what you expect to happen. See |
@ry There really isn't a fully programmatic test case. Is that what you mean by a "simple test case". No node.js library (node-websocket-client, websocket-node, etc) correctly emulates how browsers have implemented WebSockets. The easiest way to reproduce this right now is to
|
I can confirm that the fix from @indutny resolves this issue in his pull request. In both Firefox 7 and Chrome 14. I'm merging this into master. |
This should be fixed in |
@indexzero fix confirmed |
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)
The text was updated successfully, but these errors were encountered: