Permalink
Browse files

added mtime for Deflater.gzip and fixed gzip spec

  • Loading branch information...
1 parent 6967688 commit d2d51ff05966b36c40dc9439437e82d0a23f2b88 @sophiebits sophiebits committed with Jul 4, 2008
Showing with 10 additions and 3 deletions.
  1. +5 −2 lib/rack/deflater.rb
  2. +5 −1 test/spec_rack_deflater.rb
View
@@ -1,5 +1,6 @@
require "zlib"
require "stringio"
+require "time"
module Rack
@@ -17,7 +18,8 @@ def call(env)
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 @@ def call(env)
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
@@ -41,7 +41,11 @@ class << body; def each; yield("foo"); yield("bar"); end; end
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

0 comments on commit d2d51ff

Please sign in to comment.