Skip to content

Commit 19904be

Browse files
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 <[email protected]>
1 parent a72865b commit 19904be

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/rp2_common/pico_lwip/tools/makefsdata.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def process_file(input_dir, file):
1919
results = []
2020

2121
# Check content type
22-
content_type, _ = mimetypes.guess_type(file)
22+
content_type, content_encoding = mimetypes.guess_type(file)
2323
if content_type is None:
2424
content_type = "application/octet-stream"
2525

@@ -53,9 +53,15 @@ def process_file(input_dir, file):
5353
comment = f"\"Content-Length: {file_size}\" ({len(data)} chars)"
5454
results.append({'data': bytes(data, "utf-8"), 'comment': comment});
5555

56-
# content type
57-
data = f"Content-Type: {content_type}\r\n\r\n"
58-
comment = f"\"Content-Type: {content_type}\" ({len(data)} chars)"
56+
# content type and content encoding
57+
content_type_header = f"Content-Type: {content_type}"
58+
if content_encoding is None:
59+
data = f"{content_type_header}\r\n\r\n"
60+
comment = f"\"{content_type_header}\" ({len(data)} chars)"
61+
else:
62+
content_encoding_header = f"Content-Encoding: {content_encoding}"
63+
data = f"{content_type_header}\r\n{content_encoding_header}\r\n\r\n"
64+
comment = f"\"{content_type_header} {content_encoding_header}\" ({len(data)} chars)"
5965
results.append({'data': bytes(data, "utf-8"), 'comment': comment});
6066

6167
# file contents

0 commit comments

Comments
 (0)