Connection and update headers required
I have the gem working locally without any snags, but I encountered an issue trying to run the app on my cloud development environment.
In the browser, I see this error:
WebSocket connection to 'ws://ruby-on-rails-192116.nitrousapp.com/' failed: Error during WebSocket handshake: Unexpected response code: 500
In my Sinatra server logs, I see this:
2016-07-06 18:47:46 - EventMachine::WebSocket::HandshakeError - Connection and Upgrade headers requir
ed:
/home/nitrous/vidstream/.bundle/gems/em-websocket-0.3.8/lib/em-websocket/handler_factory.rb:7
3:in `build_with_request'
/home/nitrous/vidstream/.bundle/gems/sinatra-websocket-0.3.1/lib/sinatra-websocket.rb:118:in
`dispatch'
/home/nitrous/vidstream/.bundle/gems/sinatra-websocket-0.3.1/lib/sinatra-websocket.rb:22:in `
from_env'
/home/nitrous/vidstream/.bundle/gems/sinatra-websocket-0.3.1/lib/sinatra-websocket/ext/sinatr
a/request.rb:17:in `websocket'
The only difference I know of is that on my local environment, the host is localhost, but on the cloud environment it is 0.0.0.0. Unless there is some dependency which I am forgetting to install to the cloud box.
I've tried to use https or wss, but haven't managed to find something that works
Same here, could you fix it?
If you use nginx as your reverse proxy, it sends the header
Connection: upgrade
which is perfectly in line with the RFC but doesn't work with Sinatra
For me it was enough to make nginx send
Connection: Upgrade
instead.
This is clearly a bug in the application library but I was unable to identify which library the problem is in yet... could be em-websocket, could be the http/parser, could be something else...
Took me a couple of hours of tcpdumping the thing to figure this out.