From 6581f96b70274194f0f1ea4a3cea8de1fc033f5c Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Fri, 16 Mar 2018 12:06:03 -0500 Subject: [PATCH] Add fix for HTTP::Cookies --- src/cookie_fix.cr | 28 ++++++++++++++++++++++++++++ src/invidious.cr | 1 + 2 files changed, 29 insertions(+) create mode 100644 src/cookie_fix.cr 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 diff --git a/src/invidious.cr b/src/invidious.cr index 62d73cef..6796008f 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -20,6 +20,7 @@ require "pg" require "xml" require "yaml" require "./helpers" +require "./cookie_fix" CONFIG = Config.from_yaml(File.read("config/config.yml"))