Skip to content

Commit

Permalink
factored out websocket/request handling
Browse files Browse the repository at this point in the history
  • Loading branch information
collin committed Nov 14, 2012
1 parent 2430cd5 commit 06d915a
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions lib/reel/rack_worker.rb
@@ -1,6 +1,7 @@
module Reel
class RackWorker
include Celluloid
include Celluloid::Logger

INITIAL_BODY = ''

Expand Down Expand Up @@ -62,19 +63,37 @@ def initialize(handler)

def handle(connection)
while request = connection.request
begin
env = rack_env(request, connection)
status, headers, body_parts = @app.call(env)
body = response_body(body_parts)

connection.respond Response.new(status, headers, body)
ensure
body.close if body.respond_to?(:close)
body_parts.close if body_parts.respond_to?(:close)
case request
when Request
handle_request(request, connection)
when WebSocket
handle_websocket(request, connection)
end
end
end

def handle_request(request, connection)
debug "Handle Request"
env = rack_env(request, connection)
status, headers, body_parts = @handler.rack_app.call(env)
body = response_body(body_parts)

connection.respond Response.new(status, headers, body)
ensure
body.close if body.respond_to?(:close)
body_parts.close if body_parts.respond_to?(:close)
end

def handle_websocket(request, connection)
debug "Handle Websocket"
env = rack_env(request, connection)
@handler.rack_app.call(env)
# while next_app = app.send(:instance_variable_get, :@app)
# app = next_app
# end
# app.call(env)
end

def response_body(body_parts)
if body_parts.respond_to?(:to_path)
File.new(body_parts.to_path)
Expand Down

0 comments on commit 06d915a

Please sign in to comment.