diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-01-18 02:35:33 +0000 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-04-27 16:39:44 -0700 |
commit | 37d2b2fe40667eb0a7ff89111713832be934aa9f (patch) | |
tree | 04f062ca3944f21d96310ad35da5836e64b91b1e /test/spec_deflater.rb | |
parent | c6c5060fcbc71b10001807dc594f7c4a832ecd2b (diff) | |
download | rack-37d2b2fe40667eb0a7ff89111713832be934aa9f.tar.gz |
deflater flushes each chunk of the response
This allows clients to receive streaming response bodies as
they're generated by the application, not only when it's ideal
for zlib. Space-efficiency is hurt somewhat, but there's no
other way to allow this middleware to work without completely
breaking otherwise valid applications.
Diffstat (limited to 'test/spec_deflater.rb')
-rw-r--r-- | test/spec_deflater.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/spec_deflater.rb b/test/spec_deflater.rb index 43c8c95f..0c9d060b 100644 --- a/test/spec_deflater.rb +++ b/test/spec_deflater.rb @@ -35,6 +35,25 @@ describe Rack::Deflater do inflate(buf).should.equal("foobar") end + should "flush deflated chunks to the client as they become ready" do + body = Object.new + class << body; def each; yield("foo"); yield("bar"); end; end + + response = build_response(200, body, "deflate") + + response[0].should.equal(200) + response[1].should.equal({ + "Content-Encoding" => "deflate", + "Vary" => "Accept-Encoding" + }) + buf = [] + inflater = Zlib::Inflate.new(-Zlib::MAX_WBITS) + response[2].each { |part| buf << inflater.inflate(part) } + buf << inflater.finish + buf.delete_if { |part| part.empty? } + buf.should.equal(%w(foo bar)) + end + # TODO: This is really just a special case of the above... should "be able to deflate String bodies" do response = build_response(200, "Hello world!", "deflate") @@ -69,6 +88,25 @@ describe Rack::Deflater do gz.close end + should "flush gzipped chunks to the client as they become ready" do + body = Object.new + class << body; def each; yield("foo"); yield("bar"); end; end + + response = build_response(200, body, "gzip") + + response[0].should.equal(200) + response[1].should.equal({ + "Content-Encoding" => "gzip", + "Vary" => "Accept-Encoding" + }) + buf = [] + inflater = Zlib::Inflate.new(Zlib::MAX_WBITS + 32) + response[2].each { |part| buf << inflater.inflate(part) } + buf << inflater.finish + buf.delete_if { |part| part.empty? } + buf.should.equal(%w(foo bar)) + end + should "be able to fallback to no deflation" do response = build_response(200, "Hello world!", "superzip") |