sinatra-websocket icon indicating copy to clipboard operation
sinatra-websocket copied to clipboard

Connection and update headers required

Open MaxPleaner opened this issue 9 years ago • 2 comments

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

MaxPleaner avatar Jul 06 '16 18:07 MaxPleaner

Same here, could you fix it?

IJustDev avatar Apr 27 '23 09:04 IJustDev

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.

jficz avatar Jun 16 '23 08:06 jficz