Skip to content

Commit 141a3a8

Browse files
samuel-williams-shopifyioquatix
authored andcommitted
Completely eradicate the use of invoked. Fixes rack#2305.
1 parent 4b18ee1 commit 141a3a8

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

SPEC.rdoc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ The error stream. See the section below on the error stream for more information
140140

141141
==== <tt>rack.response_finished</tt>
142142

143-
If present, an array of callables that will be run by the server after the response has been processed. The callables are called with <tt>environment, status, headers, error</tt> arguments and should not raise any exceptions. The callables would typically be called after sending the response to the client, but it could also be called if an error occurs while generating the response or sending the response (in that case, the +error+ argument will be a kind of +Exception+). The callables will be invoked in reverse order.
143+
If present, an array of callables that will be run by the server after the response has been processed. The callables are called with <tt>environment, status, headers, error</tt> arguments and should not raise any exceptions. The callables would typically be called after sending the response to the client, but it could also be called if an error occurs while generating the response or sending the response (in that case, the +error+ argument will be a kind of +Exception+). The callables will be called in reverse order.
144144

145145
=== The Input Stream
146146

@@ -181,7 +181,7 @@ Partial hijack is used for bi-directional streaming of the request and response
181181

182182
If <tt>rack.hijack?</tt> is present in +env+ and truthy, an application may set the special response header <tt>rack.hijack</tt> to an object that responds to +call+, accepting a +stream+ argument.
183183

184-
After the response status and headers have been sent, this hijack 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 <tt>rack.hijack</tt> response header is present. Using an empty +Array+ is recommended.
184+
After the response status and headers have been sent, this hijack callback will be called 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 <tt>rack.hijack</tt> response header is present. Using an empty +Array+ is recommended.
185185

186186
The special response header <tt>rack.hijack</tt> must only be set if the request +env+ has a truthy <tt>rack.hijack?</tt>.
187187

@@ -239,15 +239,15 @@ If the Body responds to +to_path+, it must return either +nil+ or a +String+. If
239239

240240
==== Enumerable Body
241241

242-
The Enumerable Body must respond to +each+. It must only be called once. It must not be called after being closed, and must only yield +String+ values.
242+
The Enumerable Body must respond to +each+. It must only be consumed once (calling this method consumes the body). It must not be called after being closed, and must only yield +String+ values.
243243

244244
Middleware must not call +each+ directly on the Body. Instead, middleware can return a new Body that calls +each+ on the original Body, yielding at least once per iteration.
245245

246246
If the Body responds to +to_ary+, it must return an +Array+ whose contents are identical to that produced by calling +each+. Middleware may call +to_ary+ directly on the Body and return a new Body in its place. In other words, middleware can only process the Body directly if it responds to +to_ary+. If the Body responds to both +to_ary+ and +close+, its implementation of +to_ary+ must call +close+.
247247

248248
==== Streaming Body
249249

250-
The Streaming Body must respond to +call+. It must only be called once. It must not be called after being closed. It takes a +stream+ argument.
250+
The Streaming Body must respond to +call+. It must only be consumed once (calling this method consumes the body). It must not be called after being closed. It takes a +stream+ argument.
251251

252252
The +stream+ argument must respond to: +read+, +write+, <tt><<</tt>, +flush+, +close+, +close_read+, +close_write+, and +closed?+. The semantics of these +IO+ methods must be a best effort match to those of a normal Ruby +IO+ or +Socket+ object, using standard arguments and raising standard exceptions. Servers may simply pass on real +IO+ objects to the Streaming Body. In some cases (e.g. when using <tt>transfer-encoding</tt> or <tt>HTTP/2+</tt>), the server may need to provide a wrapper that implements the required methods, in order to provide the correct semantics.
253253

lib/rack/lint.rb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def initialize(app, env)
8282
@status = nil
8383
@headers = nil
8484
@body = nil
85-
@invoked = nil
85+
@consumed = nil
8686
@content_length = nil
8787
@closed = false
8888
@size = 0
@@ -467,7 +467,7 @@ def check_environment(env)
467467
##
468468
## ==== <tt>rack.response_finished</tt>
469469
##
470-
## If present, an array of callables that will be run by the server after the response has been processed. The callables are called with <tt>environment, status, headers, error</tt> arguments and should not raise any exceptions. The callables would typically be called after sending the response to the client, but it could also be called if an error occurs while generating the response or sending the response (in that case, the +error+ argument will be a kind of +Exception+). The callables will be invoked in reverse order.
470+
## If present, an array of callables that will be run by the server after the response has been processed. The callables are called with <tt>environment, status, headers, error</tt> arguments and should not raise any exceptions. The callables would typically be called after sending the response to the client, but it could also be called if an error occurs while generating the response or sending the response (in that case, the +error+ argument will be a kind of +Exception+). The callables will be called in reverse order.
471471
if rack_response_finished = env[RACK_RESPONSE_FINISHED]
472472
raise LintError, "rack.response_finished must be an array of callable objects" unless rack_response_finished.is_a?(Array)
473473
rack_response_finished.each do |callable|
@@ -656,7 +656,7 @@ def check_hijack_response(headers, env)
656656
end
657657
end
658658
##
659-
## After the response status and headers have been sent, this hijack 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 <tt>rack.hijack</tt> response header is present. Using an empty +Array+ is recommended.
659+
## After the response status and headers have been sent, this hijack callback will be called 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 <tt>rack.hijack</tt> response header is present. Using an empty +Array+ is recommended.
660660
else
661661
##
662662
## The special response header <tt>rack.hijack</tt> must only be set if the request +env+ has a truthy <tt>rack.hijack?</tt>.
@@ -858,13 +858,13 @@ def each
858858
## The Enumerable Body must respond to +each+. \
859859
raise LintError, "Enumerable Body must respond to each" unless @body.respond_to?(:each)
860860

861-
## It must only be called once. \
862-
raise LintError, "Response body must only be invoked once (#{@invoked})" unless @invoked.nil?
861+
## It must only be consumed once (calling this method consumes the body). \
862+
raise LintError, "Response body must only be consumed once (#{@consumed})" unless @consumed.nil?
863863

864864
## It must not be called after being closed, \
865865
raise LintError, "Response body is already closed" if @closed
866866

867-
@invoked = :each
867+
@consumed = :each
868868

869869
@body.each do |chunk|
870870
## and must only yield +String+ values.
@@ -924,13 +924,13 @@ def call(stream)
924924
## The Streaming Body must respond to +call+. \
925925
raise LintError, "Streaming Body must respond to call" unless @body.respond_to?(:call)
926926

927-
## It must only be called once. \
928-
raise LintError, "Response body must only be invoked once (#{@invoked})" unless @invoked.nil?
927+
## It must only be consumed once (calling this method consumes the body). \
928+
raise LintError, "Response body must only be consumed once (#{@consumed})" unless @consumed.nil?
929929

930930
## It must not be called after being closed. \
931931
raise LintError, "Response body is already closed" if @closed
932932

933-
@invoked = :call
933+
@consumed = :call
934934

935935
## It takes a +stream+ argument.
936936
##

test/spec_lint.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ def body.to_path; nil end
662662
body.each { |part| }
663663
body.each { |part| }
664664
}.must_raise(Rack::Lint::LintError).
665-
message.must_equal 'Response body must only be invoked once (each)'
665+
message.must_equal 'Response body must only be consumed once (each)'
666666

667667
lambda {
668668
body = Rack::Lint.new(lambda { |env|
@@ -796,7 +796,7 @@ def to_path.to_path; false end
796796
body.call(StringIO.new)
797797
body.call(nil)
798798
}.must_raise(Rack::Lint::LintError).
799-
message.must_equal 'Response body must only be invoked once (call)'
799+
message.must_equal 'Response body must only be consumed once (call)'
800800

801801
lambda {
802802
body = Rack::Lint.new(lambda { |env|

0 commit comments

Comments
 (0)