module Sinatra::Hijacker
Constants
- VERSION
Public Class Methods
registered(app)
click to toggle source
# File lib/sinatra/hijacker.rb, line 27 def self.registered app app.helpers do def ws env['sinatra.hijacker.websocket'] end end end
Public Instance Methods
call(env)
click to toggle source
Calls superclass method
# File lib/sinatra/hijacker.rb, line 8 def call env if websocket? env env['sinatra.hijacker.websocket'] = Tubesock.hijack(env).tap &:listen env['REQUEST_METHOD'] = 'WEBSOCKET' super [101, {}, []] else super end end
websocket(path, opts = {}, &bk)
click to toggle source
# File lib/sinatra/hijacker.rb, line 35 def websocket(path, opts = {}, &bk) route 'WEBSOCKET', path, opts, &bk end
websocket?(env)
click to toggle source
Taken from github.com/simulacre/sinatra-websocket/ Originally taken from skinny github.com/sj26/skinny and updated to support Firefox
# File lib/sinatra/hijacker.rb, line 21 def websocket? env env['HTTP_CONNECTION'] && env['HTTP_UPGRADE'] && env['HTTP_CONNECTION'].split(',').map(&:strip).map(&:downcase).include?('upgrade') && env['HTTP_UPGRADE'].downcase == 'websocket' end
ws()
click to toggle source
# File lib/sinatra/hijacker.rb, line 29 def ws env['sinatra.hijacker.websocket'] end