Skip to content

Commit de37b5e

Browse files
authored
last-modified, if-modified-since and if-unmodified-since are Dates. (#38)
1 parent 8dbc6a1 commit de37b5e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

lib/protocol/http/headers.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,13 @@ def []= key, value
241241
'set-cookie' => Header::SetCookie,
242242
'cookie' => Header::Cookie,
243243

244+
# Date headers:
245+
# These headers include a comma as part of the formatting so they can't be concatenated.
244246
'date' => Header::Date,
245247
'expires' => Header::Date,
248+
'last-modified' => Header::Date,
249+
'if-modified-since' => Header::Date,
250+
'if-unmodified-since' => Header::Date,
246251
}.tap{|hash| hash.default = Split}
247252

248253
# Delete all headers with the given key, and return the merged value.

test/protocol/http/header/date.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,23 @@
4343
)
4444
end
4545
end
46+
47+
describe Protocol::HTTP::Headers do
48+
let(:headers) {
49+
subject[[
50+
['Date', 'Wed, 21 Oct 2015 07:28:00 GMT'],
51+
['Expires', 'Wed, 21 Oct 2015 07:28:00 GMT'],
52+
['Last-Modified', 'Wed, 21 Oct 2015 07:28:00 GMT'],
53+
['If-Modified-Since', 'Wed, 21 Oct 2015 07:28:00 GMT'],
54+
['If-Unmodified-Since', 'Wed, 21 Oct 2015 07:28:00 GMT']
55+
]]
56+
}
57+
58+
it "should parse date headers" do
59+
# When you convert headers into a hash, the policy is applied (i.e. conversion to Date instances):
60+
headers.to_h.each do |key, value|
61+
expect(value).to be_a(Protocol::HTTP::Header::Date)
62+
end
63+
end
64+
end
4665
end

0 commit comments

Comments
 (0)