Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Websocket header missing

I'm using the 'faye' gem with Rails 3.2.13. In development I'm running faye on localhost:9292 and my app on localhost:3000. I'm able to activate pop-up windows with a curl request from the command line but I can't establish a connection from within my app. The error I'm getting in my console is:

WebSocket connection to 'ws://localhost:9292/faye' failed: Error during WebSocket handshake: 'Upgrade' header is missing

I am trying to define a header for faye in my application.js file:

$(function() {
  var faye = new Faye.Client("http://localhost:9292/faye");
  faye.setHeader("Access-Control-Allow-Origin", "http://localhost:3000");
  faye.subscribe('/messages', function (data) {
  alert(data);
  });
});

Is this the right way to add a Header?

I found a discussion of a similar problem here: https://github.com/faye/faye/issues/222 In this case the error seemed to be related to the ssl settings not being loaded. I checked my rack gem's lib directory and found

def ssl?
  scheme == 'https'
end

This seems fine. How do I know if the settings aren't being properly loaded?

Any clues about where to look next would be much appreciated.

like image 367
DizzyDez Avatar asked Aug 17 '13 07:08

DizzyDez


1 Answers

I had the same issue while following Ryan Bates's railscast: http://railscasts.com/episodes/260-messaging-with-faye

The Faye web socket server requires an adapter to run on Thin web server and send the upgrade header.

Adding this line to your Faye rackup file (.ru) will load the adapter via rack middleware:

Faye::WebSocket.load_adapter('thin')

I found this solution here: https://github.com/ryanb/private_pub/issues/39#issuecomment-4225647

like image 128
Mike Lyons Avatar answered Oct 14 '22 03:10

Mike Lyons