Skip to content

Commit 7550d42

Browse files
authored
Stream responses from httpx within pyodide (#153)
* Stream responses from httpx within pyodide * Bump version
1 parent c74d4d9 commit 7550d42

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

cirro/helpers/pyodide_patch_httpx.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,20 @@ def _send_single_request(self: Client, request: Request) -> Response:
3838
headers=request.headers,
3939
data=request.content,
4040
auth=auth_patched,
41+
stream=True
4142
)
4243

44+
# If the response is not successful, raise an HTTPError
45+
if not resp.ok:
46+
raise httpx.HTTPStatusError(
47+
f"HTTP request failed with status code {resp.status_code}",
48+
request=request,
49+
response=resp
50+
)
51+
52+
# Read the content of the response and decode it
53+
content = resp.raw.read(decode_content=True)
54+
4355
# Remove content-encoding header to prevent httpx from trying to decode the content
4456
# since requests already decodes the content
4557
if "content-encoding" in resp.headers:
@@ -49,7 +61,7 @@ def _send_single_request(self: Client, request: Request) -> Response:
4961
response = Response(
5062
status_code=resp.status_code,
5163
headers=Headers(resp.headers),
52-
content=resp.content,
64+
content=content,
5365
request=httpx.Request(method=resp.request.method, url=str(resp.url)),
5466
)
5567

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cirro"
3-
version = "1.5.2"
3+
version = "1.5.3"
44
description = "CLI tool and SDK for interacting with the Cirro platform"
55
authors = ["Cirro Bio <[email protected]>"]
66
license = "MIT"

0 commit comments

Comments
 (0)