Skip to content

responses with transfer-encoding break the urllib handler #45

Description

@machineonamission

So, yall construct a fake full HTTP response here

headers_without_content_length = {
k: v for k, v in resp.headers.items() if k != "content-length"
}
response_data = (
b"HTTP/1.1 "
+ str(resp.status_code).encode("ascii")
+ b"\n"
+ "\n".join(
f"{key}: {value}" for key, value in headers_without_content_length.items()
).encode("ascii")
+ b"\n\n"
+ resp.body
)

now, some http requests have transfer-encoding, where the data is chunked or zipped or something. problem is, XMLHttpRequest abstracts that away, but leaves the response headers. So JS passes decoded data, but says its chunked, which freaks out python's http lib.

the fix is simple, strip the transfer-encoding header before constructing the response.

this is confirmed working with chunked transferring. i am not 100% sure of gzip and such, but i imagine the same applies.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions