From fd6c9ef0799de15b2a39c95b831c11f904b5a9a7 Mon Sep 17 00:00:00 2001 From: David McKee Date: Thu, 6 Apr 2023 18:43:35 +0100 Subject: [PATCH] Provoke AWS into sending Content-Length header head used to get content lengths, but does not any more, unless Accept-Encoding is unset, presumably because compressed files might have different lengths (unsure if a requests or AWS change) --- judgments/views/detail.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/judgments/views/detail.py b/judgments/views/detail.py index 2494f68c0..747927670 100644 --- a/judgments/views/detail.py +++ b/judgments/views/detail.py @@ -112,7 +112,9 @@ def detail_xml(_request, judgment_uri): def get_pdf_size(judgment_uri): """Return the size of the S3 PDF for a judgment as a string in brackets, or an empty string if unavailable""" - response = requests.head(get_pdf_uri(judgment_uri)) + response = requests.head( + get_pdf_uri(judgment_uri), headers={"Accept-Encoding": None} + ) content_length = response.headers.get("Content-Length", None) if content_length: filesize = filesizeformat(int(content_length))