Skip to content

Commit f4471f2

Browse files
authored
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.
1 parent ee68c78 commit f4471f2

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/rp2_common/pico_lwip/tools/makefsdata.py

Lines changed: 8 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,13 @@ 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+
if content_encoding is None:
58+
data = f"Content-Type: {content_type}\r\n\r\n"
59+
comment = f"\"Content-Type: {content_type}\" ({len(data)} chars)"
60+
else:
61+
data = f"Content-Type: {content_type}\r\nContent-Encoding: {content_encoding}\r\n\r\n"
62+
comment = f"\"Content-Type: {content_type} Content-Encoding: {content_encoding}\" ({len(data)} chars)"
5963
results.append({'data': bytes(data, "utf-8"), 'comment': comment});
6064

6165
# file contents

0 commit comments

Comments
 (0)