lib/rack/lint.rb in rack-3.0.0.beta1 vs lib/rack/lint.rb in rack-3.0.0.rc1
- old
+ new
@@ -361,10 +361,24 @@
end
## <tt>SCRIPT_NAME</tt> never should be <tt>/</tt>, but instead be empty.
unless env[SCRIPT_NAME] != "/"
raise LintError, "SCRIPT_NAME cannot be '/', make it '' and PATH_INFO '/'"
end
+
+ ## <tt>rack.response_finished</tt>:: An array of callables run by the server after the response has been
+ ## processed. This would typically be invoked after sending the response to the client, but it could also be
+ ## invoked if an error occurs while generating the response or sending the response; in that case, the error
+ ## argument will be a subclass of +Exception+.
+ ## The callables are invoked with +env, status, headers, error+ arguments and should not raise any
+ ## exceptions. They should be invoked in reverse order of registration.
+ if callables = env[RACK_RESPONSE_FINISHED]
+ raise LintError, "rack.response_finished must be an array of callable objects" unless callables.is_a?(Array)
+
+ callables.each do |callable|
+ raise LintError, "rack.response_finished values must respond to call(env, status, headers, error)" unless callable.respond_to?(:call)
+ end
+ end
end
##
## === The Input Stream
##
@@ -462,13 +476,14 @@
end
yield line
}
end
- ## * +close+ must never be called on the input stream.
+ ## * +close+ can be called on the input stream to indicate that the
+ ## any remaining input is not needed.
def close(*args)
- raise LintError, "rack.input#close must not be called"
+ @input.close(*args)
end
end
##
## === The Error Stream
@@ -580,11 +595,11 @@
## callback will be invoked with a +stream+ argument which follows the
## same interface as outlined in "Streaming Body". Servers must
## ignore the +body+ part of the response tuple when the
## +rack.hijack+ response header is present. Using an empty +Array+
## instance is recommended.
- else
+ else
##
## The special response header +rack.hijack+ must only be set
## if the request +env+ has a truthy +rack.hijack?+.
if headers.key?(RACK_HIJACK)
raise LintError, 'rack.hijack header must not be present if server does not support hijacking'
@@ -844,11 +859,11 @@
@invoked = :call
## It takes a +stream+ argument.
##
## The +stream+ argument must implement:
- ## <tt>read, write, flush, close, close_read, close_write, closed?</tt>
+ ## <tt>read, write, <<, flush, close, close_read, close_write, closed?</tt>
##
@body.call(StreamWrapper.new(stream))
end
class StreamWrapper
@@ -858,10 +873,10 @@
## those of a normal Ruby IO or Socket object, using standard arguments
## and raising standard exceptions. Servers are encouraged to simply
## pass on real IO objects, although it is recognized that this approach
## is not directly compatible with HTTP/2.
REQUIRED_METHODS = [
- :read, :write, :flush, :close,
+ :read, :write, :<<, :flush, :close,
:close_read, :close_write, :closed?
]
def_delegators :@stream, *REQUIRED_METHODS