Skip to content
This repository
Browse code

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

…re, as it's contended. Left notes for future discussion.
  • Loading branch information...
commit a976537cd0134a8c65ca0b180533640e693f35d9 1 parent 68b4251
James Tucker raggi authored

Showing 2 changed files with 10 additions and 12 deletions. Show diff stats Hide diff stats

  1. +0 5 lib/rack/content_length.rb
  2. +10 7 test/spec_content_length.rb
5 lib/rack/content_length.rb
@@ -15,13 +15,8 @@ def call(env)
15 15 headers = HeaderHash.new(headers)
16 16
17 17 if !STATUS_WITH_NO_ENTITY_BODY.include?(status.to_i) &&
18   - headers['Connection'] != 'close' &&
19 18 !headers['Content-Length'] &&
20 19 !headers['Transfer-Encoding'] &&
21   - # XXX this should likely be removed, but doing so will mean it will
22   - # set content length for variable length bodies. This is better
23   - # behavior and streaming should be done with explicitly connection:
24   - # close or the chunked middleware.
25 20 body.respond_to?(:to_ary)
26 21
27 22 obody = body
17 test/spec_content_length.rb
@@ -34,18 +34,21 @@ def body.each ; yield call ; end
34 34 response[1]['Content-Length'].should.equal nil
35 35 end
36 36
37   - should "not force a Content-Length when Connection:close" do
38   - app = lambda { |env| [200, {'Connection' => 'close'}, []] }
39   - response = Rack::ContentLength.new(app).call({})
40   - response[1]['Content-Length'].should.equal nil
41   - end
  37 + # Using "Connection: close" for this is fairly contended. It might be useful
  38 + # to have some other way to signal this.
  39 + #
  40 + # should "not force a Content-Length when Connection:close" do
  41 + # app = lambda { |env| [200, {'Connection' => 'close'}, []] }
  42 + # response = Rack::ContentLength.new(app).call({})
  43 + # response[1]['Content-Length'].should.equal nil
  44 + # end
42 45
43 46 should "close bodies that need to be closed" do
44 47 body = Struct.new(:body) do
45 48 attr_reader :closed
46 49 def each; body.join; end
47 50 def close; @closed = true; end
48   - def to_ary; end # XXX remove - see note in implementation
  51 + def to_ary; end
49 52 end.new(%w[one two three])
50 53
51 54 app = lambda { |env| [200, {}, body] }
@@ -58,7 +61,7 @@ def to_ary; end # XXX remove - see note in implementation
58 61 def each
59 62 yield body.shift until body.empty?
60 63 end
61   - def to_ary; end # XXX remove - see note in implementation
  64 + def to_ary; end
62 65 end.new(%w[one two three])
63 66
64 67 app = lambda { |env| [200, {}, body] }

0 comments on commit a976537

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