Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

remove rack dep, add fwd to ping #189

Merged
merged 3 commits into from
Apr 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions lib/reel/websocket.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'forwardable'
require 'websocket/driver'
require 'rack'

module Reel
class WebSocket
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion reel.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down