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.
So, yall construct a fake full HTTP response here
pyodide-http/pyodide_http/_urllib.py
Lines 38 to 50 in b5fc794
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-encodingheader before constructing the response.this is confirmed working with
chunkedtransferring. i am not 100% sure of gzip and such, but i imagine the same applies.