From 0e6b04043e8d61d06faa568dd82160aa6a2e53c2 Mon Sep 17 00:00:00 2001 From: Merlijn Wajer Date: Mon, 11 Dec 2023 17:03:31 +0100 Subject: [PATCH] core: send: read body if file If request.body is a file(-like) interface, read the full contents and then send it. See https://github.com/koenvo/pyodide-http/issues/38 --- pyodide_http/_core.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyodide_http/_core.py b/pyodide_http/_core.py index 1cb711d..d957be4 100644 --- a/pyodide_http/_core.py +++ b/pyodide_http/_core.py @@ -118,7 +118,12 @@ def send(request: Request, stream: bool = False) -> Response: if name.lower() not in HEADERS_TO_IGNORE: xhr.setRequestHeader(name, value) - xhr.send(to_js(request.body)) + body = request.body + + if hasattr(body, 'read'): + body = body.read() + + xhr.send(to_js(body)) headers = dict(Parser().parsestr(xhr.getAllResponseHeaders()))