Rename the custom middleware to ensure it's know this is a localemiddleware. Also ensure we delete the Vary header, it could be empty - still problematic

This commit is contained in:
Oliver Falk
2025-09-11 19:54:40 +02:00
parent c6e1583e7e
commit d720fcfa50
2 changed files with 7 additions and 2 deletions

View File

@@ -31,7 +31,7 @@ INSTALLED_APPS.extend(
MIDDLEWARE.extend( MIDDLEWARE.extend(
[ [
"ivatar.middleware.RemoveVaryForImagesMiddleware", "ivatar.middleware.CustomLocaleMiddleware",
] ]
) )
MIDDLEWARE.insert( MIDDLEWARE.insert(

View File

@@ -7,7 +7,7 @@ from django.utils.deprecation import MiddlewareMixin
from django.middleware.locale import LocaleMiddleware from django.middleware.locale import LocaleMiddleware
class RemoveVaryForImagesMiddleware(LocaleMiddleware): class CustomLocaleMiddleware(LocaleMiddleware):
""" """
Middleware that extends LocaleMiddleware to skip Vary header processing for image URLs Middleware that extends LocaleMiddleware to skip Vary header processing for image URLs
""" """
@@ -19,6 +19,11 @@ class RemoveVaryForImagesMiddleware(LocaleMiddleware):
path.startswith(prefix) path.startswith(prefix)
for prefix in ["/avatar/", "/gravatarproxy/", "/blueskyproxy/"] for prefix in ["/avatar/", "/gravatarproxy/", "/blueskyproxy/"]
): ):
# Debug print
print(f"DEBUG: Processing image URL: {path}")
# Delete Vary from header if exists
if "Vary" in response:
del response["Vary"]
# Skip the parent's process_response to avoid adding Accept-Language to Vary # Skip the parent's process_response to avoid adding Accept-Language to Vary
return response return response