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

Commit

Permalink
Merge 2e88d19 into a273967
Browse files Browse the repository at this point in the history
  • Loading branch information
halorgium committed Apr 21, 2013
2 parents a273967 + 2e88d19 commit d8cc2e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/reel/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def respond(response, headers_or_body = {}, body = nil)
# The client disconnected early
@keepalive = false
ensure
if @keepalive
if @keepalive || body.nil?
reset_request(:header)
else
@socket.close unless @socket.closed?
Expand Down
14 changes: 14 additions & 0 deletions lib/reel/rack_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,21 @@ def handle(connection)
when WebSocket
handle_websocket(request, connection)
end
return if request.hijacked?
end
end

def handle_request(request, connection)
status, headers, body_parts = @app.call(request_env(request, connection))
return if request.hijacked?

# XXX delete is not actually part of the Rack SPEC...
if hijacking_callback = headers.delete('rack.hijack')
connection.respond Response.new(status, headers)
hijacking_callback.call(request.hijack)
return
end

body, is_stream = response_body(body_parts)
connection.respond (is_stream ? StreamResponse : Response).new(status, headers, body)
end
Expand Down Expand Up @@ -119,6 +129,10 @@ def env request
env[REQUEST_METHOD] = request.method
env[PATH_INFO] = request.path
env[QUERY_STRING] = request.query_string || ''
env["rack.hijack?"] = true
env["rack.hijack"] = proc do
env["rack.hijack_io"] ||= request.hijack
end

(_ = request.headers.delete CONTENT_TYPE_ORIG) && (env[CONTENT_TYPE] = _)
(_ = request.headers.delete CONTENT_LENGTH_ORIG) && (env[CONTENT_LENGTH] = _)
Expand Down
9 changes: 9 additions & 0 deletions lib/reel/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,17 @@ def self.read(connection)

def initialize(http_parser, connection = nil)
@http_parser, @connection = http_parser, connection
@hijacked = false
end

def hijack
@hijacked = true
@connection.detach
@connection.socket
end

def hijacked?; @hijacked; end

def body
@body ||= begin
raise "no connection given" unless @connection
Expand Down

0 comments on commit d8cc2e2

Please sign in to comment.