From 19904be31f3c9ed7879bf21f6f64e4d78910eacc Mon Sep 17 00:00:00 2001 From: rbryson74 Date: Mon, 14 Jul 2025 11:23:50 -0600 Subject: [PATCH] Update makefsdata.py to support content encoding Fixes #2548 (#2549) * 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 --- src/rp2_common/pico_lwip/tools/makefsdata.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/rp2_common/pico_lwip/tools/makefsdata.py b/src/rp2_common/pico_lwip/tools/makefsdata.py index 9ee0d88c..e50c898c 100755 --- a/src/rp2_common/pico_lwip/tools/makefsdata.py +++ b/src/rp2_common/pico_lwip/tools/makefsdata.py @@ -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