From be758b9c0311bd820be485949a5d5ea99dfabd0b Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 29 Jun 2017 01:59:51 +0000 Subject: 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. --- test/spec_deflater.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'test/spec_deflater.rb') 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', -- cgit v1.2.1