diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 366217c..6c315c5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,10 @@ Changelog ========= +* Fix the value in the ``Content-Length`` header to correctly count bytes, rather than unicode characters. + + Thanks to Haydn Greatnews in `PR #143 `__. + 1.6.0 (2023-06-14) ------------------ diff --git a/src/django_minify_html/middleware.py b/src/django_minify_html/middleware.py index b3af2fd..26b21de 100644 --- a/src/django_minify_html/middleware.py +++ b/src/django_minify_html/middleware.py @@ -55,7 +55,7 @@ def maybe_minify(self, request: HttpRequest, response: HttpResponseBase) -> None minified_content = minify_html.minify(content, **self.minify_args) response.content = minified_content if "Content-Length" in response: - response["Content-Length"] = len(minified_content) + response["Content-Length"] = len(response.content) minify_args = { "minify_css": True, diff --git a/tests/views.py b/tests/views.py index ecd3cdb..5eed8f2 100644 --- a/tests/views.py +++ b/tests/views.py @@ -5,8 +5,8 @@ from django_minify_html.decorators import no_html_minification -basic_html = b"

Hi

" -basic_html_minified = b"

Hi" +basic_html = "

Hi 👋

".encode() +basic_html_minified = "

Hi 👋".encode() def streaming(request):