diff --git a/website/contrib/code_block/tests.py b/website/contrib/code_block/tests.py index 964baff..8ec43e5 100644 --- a/website/contrib/code_block/tests.py +++ b/website/contrib/code_block/tests.py @@ -2,7 +2,7 @@ from django.test import TestCase from django.urls import reverse from pygments.styles import get_all_styles -from .utils import PYGMENTS_VERSION, PYGMENTS_VERSION_SLUG +from .utils import PYGMENTS_VERSION_SLUG class PygmentsStylesTestCase(TestCase): @@ -11,8 +11,7 @@ class PygmentsStylesTestCase(TestCase): with self.subTest(style=style): response = self.client.get(reverse("code-block:styles", args=[style])) self.assertEqual(response.status_code, 200) - self.assertEqual(response["Cache-Control"], "max-age=3600, public") - self.assertEqual(response["ETag"], f'"{PYGMENTS_VERSION}"') + self.assertEqual(response["Cache-Control"], "max-age=3600") def test_unknown_style(self) -> None: response = self.client.get(reverse("code-block:styles", args=["not-a-style"])) diff --git a/website/contrib/code_block/views.py b/website/contrib/code_block/views.py index 03ddf4a..034ccb0 100644 --- a/website/contrib/code_block/views.py +++ b/website/contrib/code_block/views.py @@ -1,18 +1,10 @@ from django.http import Http404, HttpRequest, HttpResponse -from django.views.decorators.cache import cache_control -from django.views.decorators.http import etag +from django.views.decorators.cache import cache_page from pygments.formatters.html import HtmlFormatter from pygments.util import ClassNotFound -from .utils import PYGMENTS_VERSION - -def pygments_etag(request: HttpRequest, name: str) -> str: - return PYGMENTS_VERSION - - -@etag(pygments_etag) -@cache_control(max_age=3600, public=True) +@cache_page(3600) def pygments_styles(request: HttpRequest, name: str) -> HttpResponse: try: formatter = HtmlFormatter(style=name)