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

Initial websocket support #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
16 changes: 7 additions & 9 deletions lib/reel/rack/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,25 @@ def initialize(app, options)

def on_connection(connection)
connection.each_request do |request|
if request.websocket?
request.respond :bad_request, "WebSockets not supported"
else
route_request request
end
route_request request, connection
end
end

# Compile the regex once
CONTENT_LENGTH_HEADER = %r{^content-length$}i

def route_request(request)
def route_request(request, connection)
options = {
:method => request.method,
:input => request.body.to_s,
"REMOTE_ADDR" => request.remote_addr
:method => request.method,
:input => request.body.to_s,
"REMOTE_ADDR" => request.remote_addr,
"reel.request" => request
}.merge(convert_headers(request.headers))

normalize_env(options)

status, headers, body = app.call ::Rack::MockRequest.env_for(request.url, options)
return if connection.response_state == :hijacked

if body.respond_to? :each
# If Content-Length was specified we can send the response all at once
Expand Down