Skip to content

Commit

Permalink
Merge branch 'unparseable_expires' of https://github.com/boone/rack-c…
Browse files Browse the repository at this point in the history
…ache into boone-unparseable_expires
  • Loading branch information
grosser committed Oct 8, 2015
2 parents 4bd96f0 + 3913262 commit 20b6f5c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rack/cache/response.rb
Expand Up @@ -164,6 +164,8 @@ def max_age
# The value of the Expires header as a Time object.
def expires
headers['Expires'] && Time.httpdate(headers['Expires'])
rescue ArgumentError
nil
end

# The number of seconds after which the response should no longer
Expand Down
15 changes: 15 additions & 0 deletions test/response_test.rb
Expand Up @@ -190,4 +190,19 @@
['Accept-Language', 'User-Agent', 'X-Foo']
end
end

describe '#expires' do
it 'returns nil if there is no Expires header' do
@res.headers['Expires'] = nil
@res.expires.should.be.nil
end
it 'returns a Time if the Expires header is parseable' do
@res.headers['Expires'] = "Mon, 30 Jun 2014 20:10:46 GMT"
@res.expires.should.equal Time.httpdate(@res.headers['Expires'])
end
it 'returns nil if the Expires header is not parseable' do
@res.headers['Expires'] = "Jun, 30 Mon 2014 20:10:46 GMT"
@res.expires.should.be.nil
end
end
end

0 comments on commit 20b6f5c

Please sign in to comment.