summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorTAKAHASHI Shuuji2022-12-16 02:31:25 +0900
committerGitHub2022-12-15 10:31:25 -0700
commit61fbda0ebf8b1ca7f6ac7d8515b1bd49690f48ab (patch)
tree60b0a2a87279f02b5f381b8a73c1132f97a4aca1 /core
parent2131b40ce078f2e80b6e8816a2ca6978b0b5842f (diff)
downloadtakahe-61fbda0ebf8b1ca7f6ac7d8515b1bd49690f48ab.tar.gz
takahe-61fbda0ebf8b1ca7f6ac7d8515b1bd49690f48ab.tar.bz2
takahe-61fbda0ebf8b1ca7f6ac7d8515b1bd49690f48ab.zip
Set the correct `Content-Type` header for static WebP images (#171)
Diffstat (limited to 'core')
-rw-r--r--core/views.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/core/views.py b/core/views.py
index 2772eb8..71db5fd 100644
--- a/core/views.py
+++ b/core/views.py
@@ -4,6 +4,7 @@ from django.templatetags.static import static
from django.utils.decorators import method_decorator
from django.utils.safestring import mark_safe
from django.views.generic import TemplateView, View
+from django.views.static import serve
from activities.views.timelines import Home
from core.decorators import cache_page
@@ -89,3 +90,14 @@ class FlatPage(TemplateView):
"title": self.title,
"content": mark_safe(html),
}
+
+
+def custom_static_serve(*args, **keywords):
+ """
+ Set the correct `Content-Type` header for static WebP images
+ since Django cannot guess the MIME type of WebP images.
+ """
+ response = serve(*args, **keywords)
+ if keywords["path"].endswith(".webp"):
+ response.headers["Content-Type"] = "image/webp"
+ return response