summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOmar Roth <omarroth@hotmail.com>2018-03-16 12:06:03 -0500
committerOmar Roth <omarroth@hotmail.com>2018-03-16 12:06:03 -0500
commit6581f96b70274194f0f1ea4a3cea8de1fc033f5c (patch)
treef88a45eaf6e2256be4a6ed2f24d02676a2df62a8
parentd8372aa83e910159f9639532023d9bb4d84a1054 (diff)
downloadinvidious-6581f96b70274194f0f1ea4a3cea8de1fc033f5c.tar.gz
invidious-6581f96b70274194f0f1ea4a3cea8de1fc033f5c.tar.bz2
invidious-6581f96b70274194f0f1ea4a3cea8de1fc033f5c.zip
Add fix for HTTP::Cookies
-rw-r--r--src/cookie_fix.cr28
-rw-r--r--src/invidious.cr1
2 files changed, 29 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
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"))