lib/reel/websocket.rb in reel-0.6.0.pre5 vs lib/reel/websocket.rb in reel-0.6.0
- old
+ new
@@ -1,21 +1,21 @@
require 'forwardable'
require 'websocket/driver'
+require 'rack'
module Reel
class WebSocket
extend Forwardable
include ConnectionMixin
include RequestMixin
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
@driver = ::WebSocket::Driver.rack(driver_env)
@driver.on(:close) do
@@ -96,22 +96,22 @@
attr_reader :env, :url, :socket
def_delegators :socket, :write
- 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]}
+ @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)
+
@socket = socket
end
end
class MessageStream