-
Notifications
You must be signed in to change notification settings - Fork 2k
Cannot proxy WebSockets from Firefox #690
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
It might be a bug in FF's websocket implementation, but it's not a bug that affects any other ws app I have encountered, so there does seem to be something uniquely brittle in node-http-proxy. Is there an event that fires on every incoming request, so I can start diagnosing the difference between the working and non-working requests? |
@minrk Are you running firefox without any plugins? |
My test code: 'use strict';
var httpProxy = require('http-proxy')
, WebSocketServer = require('ws').Server;
var app = new WebSocketServer({ port: 8001 });
app.on('connection', function(ws) {
ws.on('message', function(message) {
console.log('received: %s', message);
});
ws.send('something');
});
httpProxy.createServer({
target: 'ws://localhost:8001',
ws: true
}).listen(8000); Work fine on my firefox: |
Intriguing. It appears to be relevant that my websocket server behind the proxy is Tornado. Your test runs fine for me, but when it's my Tornado websocket server behind the proxy on 8001, Firefox connections never succeed. Firefox connections directly to the Tornado server, bypassing the proxy, work just fine, but proxied connections are never established. What seems particularly strange is the proxy's HTTP server 'connection' event never fires in the tornado case. How does the backend server participate in the proxy's connection event? Is there an earlier / lower level event than 'connection' that I can look at? It's never awesome when it takes the interaction of three projects to cause a problem:
|
I submitted #691, which should fix the bug here. A summary of the situation: Chrome
Firefox
If I understand the websocket protocol correctly, there are bugs in both the nodejs websocket package and node-http-proxy, which cancel each other out. The bug here: Proxy shouldn't be setting The (possible) bug in ws: Websocket server should probably not accept connections if WorkaroundI found this workaround, which just forces the value to be 'upgrade', since that's the only value that will be handled correctly. server.on('upgrade', function (req, res, head) {
req.headers.connection = 'upgrade';
proxy.ws(req, res, head);
}); A safer version could split on ',', and check for upgrade. |
This was fixed by #691 |
If I try to connect a websocket through a simple proxy from Firefox, it never triggers the upgrade event, nor proxies data to the server.
The Proxy:
Connect with the following js in Firefox:
There is no output for a few seconds, no data is proxied, then the websocket fails, sending a request with the following headers, which does get proxiedThe 'Connection' header is converted from
keep-alive, upgrade
toclose
:The same request proxies just fine from Chrome and Safari, so there's something different about how Firefox initiates websocket requests.
This is with current master (d16062b) node-http-proxy, and nodejs 0.10.30, and Firefox 31.
Update: Fixed symptom description
The text was updated successfully, but these errors were encountered: