summary refs log tree commit
path: root/test/spec_deflater.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/spec_deflater.rb')
-rw-r--r--test/spec_deflater.rb38
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")