Update makefsdata.py to support content encoding Fixes #2548 (#2549)
Some checks are pending
Bazel presubmit checks / bazel-build-check (macos-latest) (push) Waiting to run
Bazel presubmit checks / bazel-build-check (ubuntu-latest) (push) Waiting to run
Bazel presubmit checks / other-bazel-checks (push) Waiting to run
Check Configs / check-configs (push) Waiting to run
CMake / build (push) Waiting to run
Build on macOS / build (push) Waiting to run
Build on Windows / build (push) Waiting to run

* Update makefsdata.py to support content encoding

changed makefsdata.py slightly to allow it to recognize files that have been manually gzipped (e.g. "mysite.css.gz") to send the proper Content-Encoding information in the response headers.

* Code review fix

---------

Co-authored-by: Peter Harper <peter.harper@raspberrypi.com>
This commit is contained in:
rbryson74 2025-07-14 11:23:50 -06:00 committed by GitHub
parent a72865be12
commit 19904be31f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,7 +19,7 @@ def process_file(input_dir, file):
results = []
# Check content type
content_type, _ = mimetypes.guess_type(file)
content_type, content_encoding = mimetypes.guess_type(file)
if content_type is None:
content_type = "application/octet-stream"
@ -53,9 +53,15 @@ def process_file(input_dir, file):
comment = f"\"Content-Length: {file_size}\" ({len(data)} chars)"
results.append({'data': bytes(data, "utf-8"), 'comment': comment});
# content type
data = f"Content-Type: {content_type}\r\n\r\n"
comment = f"\"Content-Type: {content_type}\" ({len(data)} chars)"
# content type and content encoding
content_type_header = f"Content-Type: {content_type}"
if content_encoding is None:
data = f"{content_type_header}\r\n\r\n"
comment = f"\"{content_type_header}\" ({len(data)} chars)"
else:
content_encoding_header = f"Content-Encoding: {content_encoding}"
data = f"{content_type_header}\r\n{content_encoding_header}\r\n\r\n"
comment = f"\"{content_type_header} {content_encoding_header}\" ({len(data)} chars)"
results.append({'data': bytes(data, "utf-8"), 'comment': comment});
# file contents