diff options
Diffstat (limited to 'src/cookie_fix.cr')
| -rw-r--r-- | src/cookie_fix.cr | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/cookie_fix.cr b/src/cookie_fix.cr new file mode 100644 index 00000000..536d5887 --- /dev/null +++ b/src/cookie_fix.cr @@ -0,0 +1,28 @@ +module HTTP + class Cookie + module Parser + SetCookieStringFix = /^#{Regex::CookiePair}(?:;\s*#{Regex::CookieAV})*$/ + + def parse_set_cookie(header) + match = header.match(SetCookieStringFix) + return unless match + + expires = if max_age = match["max_age"]? + Time.now + max_age.to_i.seconds + else + parse_time(match["expires"]?) + end + + Cookie.new( + match["name"], match["value"], + path: match["path"]? || "/", + expires: expires, + domain: match["domain"]?, + secure: match["secure"]? != nil, + http_only: match["http_only"]? != nil, + extension: match["extension"]? + ) + end + end + end +end |
