mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-19 06:28:03 +00:00
Merge branch 'devel' into 'master'
Final Vary headers fix from devel See merge request oliver/ivatar!249
This commit is contained in:
@@ -31,7 +31,7 @@ INSTALLED_APPS.extend(
|
||||
|
||||
MIDDLEWARE.extend(
|
||||
[
|
||||
"django.middleware.locale.LocaleMiddleware",
|
||||
"ivatar.middleware.RemoveVaryForImagesMiddleware",
|
||||
]
|
||||
)
|
||||
MIDDLEWARE.insert(
|
||||
|
||||
@@ -4,6 +4,26 @@ Middleware classes
|
||||
"""
|
||||
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
from django.middleware.locale import LocaleMiddleware
|
||||
|
||||
|
||||
class RemoveVaryForImagesMiddleware(LocaleMiddleware):
|
||||
"""
|
||||
Middleware that extends LocaleMiddleware to skip Vary header processing for image URLs
|
||||
"""
|
||||
|
||||
def process_response(self, request, response):
|
||||
# Check if this is an image-related URL
|
||||
path = request.path
|
||||
if any(
|
||||
path.startswith(prefix)
|
||||
for prefix in ["/avatar/", "/gravatarproxy/", "/blueskyproxy/"]
|
||||
):
|
||||
# Skip the parent's process_response to avoid adding Accept-Language to Vary
|
||||
return response
|
||||
|
||||
# For all other URLs, use the parent's behavior
|
||||
return super().process_response(request, response)
|
||||
|
||||
|
||||
class MultipleProxyMiddleware(
|
||||
|
||||
@@ -43,7 +43,6 @@ MIDDLEWARE = [
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
"django.middleware.locale.LocaleMiddleware",
|
||||
]
|
||||
|
||||
ROOT_URLCONF = "ivatar.urls"
|
||||
|
||||
@@ -118,16 +118,13 @@ class AvatarImageView(TemplateView):
|
||||
if centry := caches["filesystem"].get(uri):
|
||||
# For DEBUG purpose only
|
||||
# print('Cached entry for %s' % uri)
|
||||
response = HttpResponse(
|
||||
return HttpResponse(
|
||||
centry["content"],
|
||||
content_type=centry["content_type"],
|
||||
status=centry["status"],
|
||||
reason=centry["reason"],
|
||||
charset=centry["charset"],
|
||||
)
|
||||
# Remove Vary header for images since language doesn't matter
|
||||
response["Vary"] = ""
|
||||
return response
|
||||
|
||||
# In case no digest at all is provided, return to home page
|
||||
if "digest" not in kwargs:
|
||||
|
||||
Reference in New Issue
Block a user