summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Alpert <spicyjalapeno@gmail.com>2008-07-04 12:53:43 -0600
committerChristian Neukirchen <chneukirchen@gmail.com>2008-07-06 14:18:30 +0200
commitd2d51ff05966b36c40dc9439437e82d0a23f2b88 (patch)
tree162ab82a04be875a5f6860148d625d734cd30fc3
parent69676880c39d36cd3ed718e228218b7e58946624 (diff)
downloadrack-d2d51ff05966b36c40dc9439437e82d0a23f2b88.tar.gz
added mtime for Deflater.gzip and fixed gzip spec
-rw-r--r--lib/rack/deflater.rb7
-rw-r--r--test/spec_rack_deflater.rb6
2 files changed, 10 insertions, 3 deletions
diff --git a/lib/rack/deflater.rb b/lib/rack/deflater.rb
index 1dc8b45d..20401a45 100644
--- a/lib/rack/deflater.rb
+++ b/lib/rack/deflater.rb
@@ -1,5 +1,6 @@
require "zlib"
require "stringio"
+require "time"
module Rack
@@ -17,7 +18,8 @@ class Deflater
case encoding
when "gzip"
- [status, headers.merge("Content-Encoding" => "gzip"), self.class.gzip(body)]
+ mtime = headers["Last-Modified"] || Time.now
+ [status, headers.merge("Content-Encoding" => "gzip"), self.class.gzip(body, mtime)]
when "deflate"
[status, headers.merge("Content-Encoding" => "deflate"), self.class.deflate(body)]
when "identity"
@@ -28,9 +30,10 @@ class Deflater
end
end
- def self.gzip(body)
+ def self.gzip(body, mtime=Time.now)
io = StringIO.new
gzip = Zlib::GzipWriter.new(io)
+ gzip.mtime = mtime
# TODO: Add streaming
# TODO: Consider all part types
diff --git a/test/spec_rack_deflater.rb b/test/spec_rack_deflater.rb
index 3a442419..33d984ae 100644
--- a/test/spec_rack_deflater.rb
+++ b/test/spec_rack_deflater.rb
@@ -41,7 +41,11 @@ context "Rack::Deflater" do
response[0].should.equal(200)
response[1].should.equal({ "Content-Encoding" => "gzip" })
- # response[2].to_s.should.equal("\037\213\b\000J\340mH\000\003K\313\317OJ,\002\000\225\037\366\236\006\000\000\000")
+
+ io = StringIO.new(response[2].to_s)
+ gz = Zlib::GzipReader.new(io)
+ gz.read.should.equal("foobar")
+ gz.close
end
specify "should be able to fallback to no deflation" do