summaryrefslogtreecommitdiff
path: root/test/spec_deflater.rb
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2017-06-29 01:59:51 +0000
committerEric Wong <e@80x24.org>2017-06-29 02:04:50 +0000
commitbe758b9c0311bd820be485949a5d5ea99dfabd0b (patch)
tree2bf8c37605bdffa0ae501387ff6f231240065229 /test/spec_deflater.rb
parent181e56e011f4c321895bfd01f20cccb3ec1cafa5 (diff)
downloadrack-be758b9c0311bd820be485949a5d5ea99dfabd0b.tar.gz
deflater: additional mtime tests
The next commit will reduce long-lived Time objects. Regardless of whether that commit is acceptable, having extra tests for existing mtime behavior cannot hurt. For testing responses with the Last-Modified header, setting a random date in the past should make failure to preserve mtime in the gzip header more apparent.
Diffstat (limited to 'test/spec_deflater.rb')
-rw-r--r--test/spec_deflater.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/test/spec_deflater.rb b/test/spec_deflater.rb
index 410a1438..4a337cab 100644
--- a/test/spec_deflater.rb
+++ b/test/spec_deflater.rb
@@ -44,6 +44,8 @@ describe Rack::Deflater do
[accept_encoding, accept_encoding.dup]
end
+ start = Time.now.to_i
+
# build response
status, headers, body = build_response(
options['app_status'] || expected_status,
@@ -67,6 +69,13 @@ describe Rack::Deflater do
when 'gzip'
io = StringIO.new(body_text)
gz = Zlib::GzipReader.new(io)
+ mtime = gz.mtime.to_i
+ if last_mod = headers['Last-Modified']
+ Time.httpdate(last_mod).to_i.must_equal mtime
+ else
+ mtime.must_be(:<=, Time.now.to_i)
+ mtime.must_be(:>=, start.to_i)
+ end
tmp = gz.read
gz.close
tmp
@@ -243,7 +252,7 @@ describe Rack::Deflater do
end
it 'handle gzip response with Last-Modified header' do
- last_modified = Time.now.httpdate
+ last_modified = Time.at(123).httpdate
options = {
'response_headers' => {
'Content-Type' => 'text/plain',