Repository: raspberrypi/pico-sdk
File: src/rp2_common/pico_lwip/tools/makefsdata.py (Python)

Code before:
        if file.name.startswith(f"{response_id}."):
            response_type = response_id
            break
    data = f"{response_types[response_type]}\r\n"
    comment = f"\"{response_types[response_type]}\" ({len(data)} chars)"
    results.append({'data': bytes(data, "utf-8"), 'comment': comment});

    # user agent
    data = f"Server: {HTTPD_SERVER_AGENT}\r\n"
    comment = f"\"Server: {HTTPD_SERVER_AGENT}\" ({len(data)} chars)"
    results.append({'data': bytes(data, "utf-8"), 'comment': comment});

    if file.suffix not in LWIP_HTTPD_SSI_EXTENSIONS:
        # content length
        file_size = file.stat().st_size
        data = f"Content-Length: {file_size}\r\n"
        comment = f"\"Content-Length: {file_size}\" ({len(data)} chars)"
        results.append({'data': bytes(data, "utf-8"), 'comment': comment});

    # content type and content encoding
    if content_encoding is None:
        data = f"Content-Type: {content_type}\r\n\r\n"
        comment = f"\"Content-Type: {content_type}\" ({len(data)} chars)"
    else:
        data = f"Content-Type: {content_type}\r\nContent-Encoding: {content_encoding}\r\n\r\n"
        comment = f"\"Content-Type: {content_type} Content-Encoding: {content_encoding}\" ({len(data)} chars)"
    results.append({'data': bytes(data, "utf-8"), 'comment': comment});

    # file contents
    data = file.read_bytes()
    comment = f"raw file data ({len(data)} bytes)"
    results.append({'data': data, 'comment': comment});

    return results;

def process_file_list(fd, input):
    data = []
    fd.write("#include \"lwip/apps/fs.h\"\n")
    fd.write("\n")
    # generate the page contents
    input_dir = None
    for name in input:
        file = Path(name)
        if not file.is_file():
            raise RuntimeError(f"File not found: {name}")
        # Take the input directory from the first file
        if input_dir is None:
            input_dir = file.parent
        results = process_file(input_dir, file)

        # make a variable name

Review comment (suggestion):
Just a small (untested) tidy-up suggestion:
```suggestion
    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)"
```

Code after:
        if file.name.startswith(f"{response_id}."):
            response_type = response_id
            break
    data = f"{response_types[response_type]}\r\n"
    comment = f"\"{response_types[response_type]}\" ({len(data)} chars)"
    results.append({'data': bytes(data, "utf-8"), 'comment': comment});

    # user agent
    data = f"Server: {HTTPD_SERVER_AGENT}\r\n"
    comment = f"\"Server: {HTTPD_SERVER_AGENT}\" ({len(data)} chars)"
    results.append({'data': bytes(data, "utf-8"), 'comment': comment});

    if file.suffix not in LWIP_HTTPD_SSI_EXTENSIONS:
        # content length
        file_size = file.stat().st_size
        data = f"Content-Length: {file_size}\r\n"
        comment = f"\"Content-Length: {file_size}\" ({len(data)} chars)"
        results.append({'data': bytes(data, "utf-8"), 'comment': comment});

    # 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
    data = file.read_bytes()
    comment = f"raw file data ({len(data)} bytes)"
    results.append({'data': data, 'comment': comment});

    return results;

def process_file_list(fd, input):
    data = []
    fd.write("#include \"lwip/apps/fs.h\"\n")
    fd.write("\n")
    # generate the page contents
    input_dir = None
    for name in input:
        file = Path(name)
        if not file.is_file():
            raise RuntimeError(f"File not found: {name}")
        # Take the input directory from the first file
        if input_dir is None:
            input_dir = file.parent
        results = process_file(input_dir, file)