mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-17 05:28:03 +00:00
Merge branch 'devel' into 'master'
Middleware and logging adjustments See merge request oliver/ivatar!250
This commit is contained in:
@@ -31,7 +31,7 @@ INSTALLED_APPS.extend(
|
||||
|
||||
MIDDLEWARE.extend(
|
||||
[
|
||||
"ivatar.middleware.RemoveVaryForImagesMiddleware",
|
||||
"ivatar.middleware.CustomLocaleMiddleware",
|
||||
]
|
||||
)
|
||||
MIDDLEWARE.insert(
|
||||
|
||||
@@ -375,9 +375,9 @@ class ConfirmedEmail(BaseAccountModel):
|
||||
cache_key = f"views.decorators.cache.cache_page.{quote(str(cache_url))}"
|
||||
if cache.has_key(cache_key):
|
||||
cache.delete(cache_key)
|
||||
logger.error("Successfully cleaned up cached page: %s" % cache_key)
|
||||
logger.debug("Successfully cleaned up cached page: %s" % cache_key)
|
||||
else:
|
||||
logger.error("Page %s wasn't cached.", cache_key)
|
||||
logger.debug("Page %s wasn't cached.", cache_key)
|
||||
|
||||
return super().save(force_insert, force_update, using, update_fields)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from django.utils.deprecation import MiddlewareMixin
|
||||
from django.middleware.locale import LocaleMiddleware
|
||||
|
||||
|
||||
class RemoveVaryForImagesMiddleware(LocaleMiddleware):
|
||||
class CustomLocaleMiddleware(LocaleMiddleware):
|
||||
"""
|
||||
Middleware that extends LocaleMiddleware to skip Vary header processing for image URLs
|
||||
"""
|
||||
@@ -19,6 +19,20 @@ class RemoveVaryForImagesMiddleware(LocaleMiddleware):
|
||||
path.startswith(prefix)
|
||||
for prefix in ["/avatar/", "/gravatarproxy/", "/blueskyproxy/"]
|
||||
):
|
||||
# Delete Vary from header if exists
|
||||
if "Vary" in response:
|
||||
del response["Vary"]
|
||||
|
||||
# Extract hash from URL path for ETag
|
||||
# URLs are like /avatar/{hash}, /gravatarproxy/{hash}, /blueskyproxy/{hash}
|
||||
path_parts = path.strip("/").split("/")
|
||||
if len(path_parts) >= 2:
|
||||
hash_value = path_parts[1] # Get the hash part
|
||||
response["Etag"] = f'"{hash_value}"'
|
||||
else:
|
||||
# Fallback to content hash if we can't extract from URL
|
||||
response["Etag"] = f'"{hash(response.content)}"'
|
||||
|
||||
# Skip the parent's process_response to avoid adding Accept-Language to Vary
|
||||
return response
|
||||
|
||||
|
||||
Reference in New Issue
Block a user