Skip to content
Browse files

Hijack SPEC changes after review discussion

  • Loading branch information...
1 parent 8a311fb commit c33efb8103c53ad89322451d8b05f134e991a33a @raggi raggi committed Jan 11, 2013
Showing with 17 additions and 4 deletions.
  1. +7 −1 SPEC
  2. +10 −3 lib/rack/lint.rb
View
8 SPEC
@@ -136,7 +136,7 @@ The error stream must respond to +puts+, +write+ and +flush+.
=== Hijacking
==== Request (before status)
If rack.hijack? is true then rack.hijack must respond to #call.
-rack.hijack should return the io that will also be assigned (or is
+rack.hijack must return the io that will also be assigned (or is
already present, in rack.hijack_io.
rack.hijack_io must respond to:
@@ -185,6 +185,12 @@ the <tt>rack.hijack</tt> response API is in use.
The special response header <tt>rack.hijack</tt> must only be set
if the request env has <tt>rack.hijack?</tt> <tt>true</tt>.
+==== Conventions
+* Middleware should not use hijack unless it is handling the whole
+ response.
+* Middleware may wrap the IO object for the response pattern.
+* Middleware should not wrap the IO object for the request pattern. The
+ request pattern is intended to provide the hijacker with "raw tcp".
== The Response
=== The Status
This is an HTTP status. When parsed as integer (+to_i+), it must be
View
13 lib/rack/lint.rb
@@ -458,9 +458,10 @@ def check_hijack(env)
original_hijack = env['rack.hijack']
assert("rack.hijack must respond to call") { original_hijack.respond_to?(:call) }
env['rack.hijack'] = proc do
- ## rack.hijack should return the io that will also be assigned (or is
+ ## rack.hijack must return the io that will also be assigned (or is
## already present, in rack.hijack_io.
- result = original_hijack.call
+ io = original_hijack.call
+ HijackWrapper.new(io)
##
## rack.hijack_io must respond to:
## <tt>read, write, read_nonblock, write_nonblock, flush, close,
@@ -483,7 +484,7 @@ def check_hijack(env)
## rack.hijack is for Rack to "get out of the way", as such, Rack only
## provides the minimum of specification and support.
env['rack.hijack_io'] = HijackWrapper.new(env['rack.hijack_io'])
- result
+ io
end
else
##
@@ -533,6 +534,12 @@ def check_hijack_response(headers, env)
}
end
end
+ ## ==== Conventions
+ ## * Middleware should not use hijack unless it is handling the whole
+ ## response.
+ ## * Middleware may wrap the IO object for the response pattern.
+ ## * Middleware should not wrap the IO object for the request pattern. The
+ ## request pattern is intended to provide the hijacker with "raw tcp".
## == The Response

0 comments on commit c33efb8

Please sign in to comment.
Something went wrong with that request. Please try again.