diff --git a/lib/reel/websocket.rb b/lib/reel/websocket.rb index 3871fb5..b723924 100644 --- a/lib/reel/websocket.rb +++ b/lib/reel/websocket.rb @@ -1,6 +1,5 @@ require 'forwardable' require 'websocket/driver' -require 'rack' module Reel class WebSocket @@ -10,10 +9,11 @@ class WebSocket attr_reader :socket def_delegators :@socket, :addr, :peeraddr + def_delegators :@driver, :ping def initialize(info, connection) - driver_env = DriverEnvironment.new(info, connection.socket) - + driver_env = DriverEnvironment.new(info, connection.socket) + @socket = connection.hijack_socket @request_info = info @@ -98,19 +98,19 @@ class DriverEnvironment def_delegators :socket, :write - def initialize(info, socket) - @url = info.url - - env_hash = Hash[info.headers.map { |key, value| ['HTTP_' + key.upcase.gsub('-','_'),value ] }] - - env_hash.merge!({ - :method => info.method, - :input => info.body.to_s, - 'REMOTE_ADDR' => info.remote_addr - }) - - @env = ::Rack::MockRequest.env_for(@url, env_hash) + RACK_HEADERS = { + 'Origin' => 'HTTP_ORIGIN', + 'Sec-WebSocket-Key' => 'HTTP_SEC_WEBSOCKET_KEY', + 'Sec-WebSocket-Key1' => 'HTTP_SEC_WEBSOCKET_KEY1', + 'Sec-WebSocket-Key2' => 'HTTP_SEC_WEBSOCKET_KEY2', + 'Sec-WebSocket-Extensions' => 'HTTP_SEC_WEBSOCKET_EXTENSIONS', + 'Sec-WebSocket-Protocol' => 'HTTP_SEC_WEBSOCKET_PROTOCOL', + 'Sec-WebSocket-Version' => 'HTTP_SEC_WEBSOCKET_VERSION' + } + def initialize(info, socket) + @env, @url = {}, info.url + RACK_HEADERS.each {|k,v| @env[v] = info.headers[k]} @socket = socket end end diff --git a/reel.gemspec b/reel.gemspec index 404ebeb..e4612f3 100644 --- a/reel.gemspec +++ b/reel.gemspec @@ -20,7 +20,6 @@ Gem::Specification.new do |gem| gem.add_runtime_dependency 'http', '>= 0.6.0.pre' gem.add_runtime_dependency 'http_parser.rb', '>= 0.6.0' gem.add_runtime_dependency 'websocket-driver', '>= 0.5.1' - gem.add_runtime_dependency 'rack' gem.add_development_dependency 'rake' gem.add_development_dependency 'rspec', '>= 2.11.0'