mirror of
https://github.com/samsonjs/http-cookie.git
synced 2026-04-26 14:47:43 +00:00
Add 1.8 compatibility.
This commit is contained in:
parent
c442e8e0c8
commit
96dabc8288
1 changed files with 21 additions and 6 deletions
|
|
@ -79,6 +79,26 @@ class HTTP::Cookie::Scanner < StringScanner
|
||||||
[name, value]
|
[name, value]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if Time.respond_to?(:strptime)
|
||||||
|
def tuple_to_time(day_of_month, month, year, time)
|
||||||
|
Time.strptime(
|
||||||
|
'%02d %s %04d %02d:%02d:%02d UTC' % [day_of_month, month, year, *time],
|
||||||
|
'%d %b %Y %T %Z'
|
||||||
|
).tap { |date|
|
||||||
|
date.day == day_of_month or return nil
|
||||||
|
}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
def tuple_to_time(day_of_month, month, year, time)
|
||||||
|
Time.parse(
|
||||||
|
'%02d %s %04d %02d:%02d:%02d UTC' % [day_of_month, month, year, *time]
|
||||||
|
).tap { |date|
|
||||||
|
date.day == day_of_month or return nil
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
private :tuple_to_time
|
||||||
|
|
||||||
def parse_cookie_date(s)
|
def parse_cookie_date(s)
|
||||||
# RFC 6265 5.1.1
|
# RFC 6265 5.1.1
|
||||||
time = day_of_month = month = year = nil
|
time = day_of_month = month = year = nil
|
||||||
|
|
@ -127,12 +147,7 @@ class HTTP::Cookie::Scanner < StringScanner
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
Time.strptime(
|
tuple_to_time(day_of_month, month, year, time)
|
||||||
'%02d %s %04d %02d:%02d:%02d UTC' % [day_of_month, month, year, *time],
|
|
||||||
'%d %b %Y %T %Z'
|
|
||||||
).tap { |date|
|
|
||||||
date.day == day_of_month or return nil
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def scan_cookie
|
def scan_cookie
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue