Skip to content

Commit

Permalink
added mtime for Deflater.gzip and fixed gzip spec
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiebits authored and leahneukirchen committed Jul 6, 2008
1 parent 6967688 commit d2d51ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/rack/deflater.rb
@@ -1,5 +1,6 @@
require "zlib"
require "stringio"
require "time"

module Rack

Expand All @@ -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"
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion test/spec_rack_deflater.rb
Expand Up @@ -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
Expand Down

0 comments on commit d2d51ff

Please sign in to comment.