Websocket header missing

匿名 (未验证) 提交于 2019-12-03 02:47:02

问题:

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.

回答1:

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.

Add this line to your Faye rackup (.ru) file:

Faye::WebSocket.load_adapter('thin')

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



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!