Skip to content
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

websocket proxy,what if the sever reject the connect with status other than 101 #627

Closed
kd128 opened this issue Apr 22, 2014 · 4 comments · Fixed by #708
Closed

websocket proxy,what if the sever reject the connect with status other than 101 #627

kd128 opened this issue Apr 22, 2014 · 4 comments · Fixed by #708

Comments

@kd128
Copy link

kd128 commented Apr 22, 2014

it happen when sever dothing like

var http = require('http');
var server = http.createServer(function (req, res) {
......//do normal request
}).listen(1337);


var accept  = function(request){
  if(ok){
    return true;
  } else {
    return false;
  }
}

server.on('upgrade',function (request, socket, head) {
      if(!accept(request)){//here the http-proxy will not work!
        socket.write("HTTP/1.1 406 Not Acceptable\r\n");
        socket.write("Connection: close\r\n");
        socket.write("\r\n");
        socket.end();
        return;
      }
       ......//do websocket request
 });
@kd128
Copy link
Author

kd128 commented Apr 22, 2014

becasue socket.write("HTTP/1.1 406 Not Acceptable\r\n"),the http proxy will just emit an response event other than upgrade event!
please fix this bug!

@kd128
Copy link
Author

kd128 commented Apr 25, 2014

please fix this bug as soon as possible,because it will make socket leave!

@jcrugzz
Copy link
Contributor

jcrugzz commented Apr 25, 2014

@kd128 Can you see if running a socket.destroy() rather than a socket.end() behaves differently? But it is possible this is a bug. If you can add a fully working, minimal test case, this would expedite the process :). And ideally in the form of a pull request ;)

@minrk
Copy link
Contributor

minrk commented Sep 30, 2014

I've added a complete test case for this bug here. Switching between socket.end and destroy does not have any effect. Proxied websocket connections that are rejected are left open. This is particularly problematic in browsers (other than Safari for some reason) because a websocket stuck in the connecting state actually blocks other attempts to connect to the same server, even from other tabs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants