From 7c53b098164c8be1beff212f0cd5d5995fc82ed5 Mon Sep 17 00:00:00 2001 From: Deimos Date: Fri, 15 Mar 2019 18:11:27 -0600 Subject: [PATCH] Theme cookie tween: only affect GET requests I was seeing some strange behavior from this tween on non-GET requests, where a huge number of Set-Cookie headers were being added. I'm not sure exactly what was causing this, but it's not necessary to do on non-GET requests anyway, so this should be safer. --- tildes/tildes/tweens.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tildes/tildes/tweens.py b/tildes/tildes/tweens.py index f1b9bfd..378598c 100644 --- a/tildes/tildes/tweens.py +++ b/tildes/tildes/tweens.py @@ -72,6 +72,10 @@ def theme_cookie_tween_factory(handler: Callable, registry: Registry) -> Callabl """Set the theme cookie if needed (currently always, see comment below).""" response = handler(request) + # only set the cookie on GET requests + if request.method.upper() != "GET": + return response + current_theme = request.cookies.get("theme", "") if not current_theme and request.user: current_theme = request.user.theme_default