From d571573e5219f453d371de7061dfcdeae31a567a Mon Sep 17 00:00:00 2001 From: Matthew McGarvey Date: Fri, 16 Oct 2020 05:23:18 -0500 Subject: [PATCH] Set preferences before conditional breaks in before_all (#1412) --- src/invidious.cr | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/invidious.cr b/src/invidious.cr index 3e03628f..29a412a1 100644 --- a/src/invidious.cr +++ b/src/invidious.cr @@ -246,12 +246,13 @@ spawn do end before_all do |env| - begin - preferences = Preferences.from_json(env.request.cookies["PREFS"]?.try &.value || "{}") + preferences = begin + Preferences.from_json(env.request.cookies["PREFS"]?.try &.value || "{}") rescue - preferences = Preferences.from_json("{}") + Preferences.from_json("{}") end + env.set "preferences", preferences env.response.headers["X-XSS-Protection"] = "1; mode=block" env.response.headers["X-Content-Type-Options"] = "nosniff" extra_media_csp = "" @@ -298,6 +299,7 @@ before_all do |env| }, HMAC_KEY, PG_DB, 1.week) preferences = user.preferences + env.set "preferences", preferences env.set "sid", sid env.set "csrf_token", csrf_token @@ -319,6 +321,7 @@ before_all do |env| }, HMAC_KEY, PG_DB, 1.week) preferences = user.preferences + env.set "preferences", preferences env.set "sid", sid env.set "csrf_token", csrf_token @@ -336,7 +339,6 @@ before_all do |env| preferences.dark_mode = dark_mode preferences.thin_mode = thin_mode preferences.locale = locale - env.set "preferences", preferences current_page = env.request.path if env.request.query