Permalink
Browse files

Return behavior against Connection: close for Content-Length middlewa…

…re, as it's contended. Left notes for future discussion.
  • Loading branch information...
1 parent 68b4251 commit a976537cd0134a8c65ca0b180533640e693f35d9 @raggi raggi committed May 20, 2011
Showing with 10 additions and 12 deletions.
  1. +0 −5 lib/rack/content_length.rb
  2. +10 −7 test/spec_content_length.rb
@@ -15,13 +15,8 @@ def call(env)
headers = HeaderHash.new(headers)
if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) &&
- headers['Connection'] != 'close' &&
!headers['Content-Length'] &&
!headers['Transfer-Encoding'] &&
- # XXX this should likely be removed, but doing so will mean it will
- # set content length for variable length bodies. This is better
- # behavior and streaming should be done with explicitly connection:
- # close or the chunked middleware.
body.respond_to?(:to_ary)
obody = body
@@ -34,18 +34,21 @@ def body.each ; yield call ; end
response[1]['Content-Length'].should.equal nil
end
- should "not force a Content-Length when Connection:close" do
- app = lambda { |env| [200, {'Connection' => 'close'}, []] }
- response = Rack::ContentLength.new(app).call({})
- response[1]['Content-Length'].should.equal nil
- end
+ # Using "Connection: close" for this is fairly contended. It might be useful
+ # to have some other way to signal this.
+ #
+ # should "not force a Content-Length when Connection:close" do
+ # app = lambda { |env| [200, {'Connection' => 'close'}, []] }
+ # response = Rack::ContentLength.new(app).call({})
+ # response[1]['Content-Length'].should.equal nil
+ # end
should "close bodies that need to be closed" do
body = Struct.new(:body) do
attr_reader :closed
def each; body.join; end
def close; @closed = true; end
- def to_ary; end # XXX remove - see note in implementation
+ def to_ary; end
end.new(%w[one two three])
app = lambda { |env| [200, {}, body] }
@@ -58,7 +61,7 @@ def to_ary; end # XXX remove - see note in implementation
def each
yield body.shift until body.empty?
end
- def to_ary; end # XXX remove - see note in implementation
+ def to_ary; end
end.new(%w[one two three])
app = lambda { |env| [200, {}, body] }

0 comments on commit a976537

Please sign in to comment.