Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions impit-python/src/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ impl ImpitPyResponse {
let content = response
.bytes()
.await
.map_err(|_| ImpitPyError(impit::errors::ImpitError::NetworkError))?;
.map_err(|error| ImpitPyError(ImpitError::from(error, None)))?;

Ok(Python::attach(|py| {
let mut slf_ref = slf.borrow_mut(py);
Expand Down Expand Up @@ -528,7 +528,7 @@ impl ImpitPyResponse {
response
.bytes()
.await
.map_err(|_| ImpitPyError(impit::errors::ImpitError::NetworkError))
.map_err(|error| ImpitPyError(ImpitError::from(error, None)))
})
})?;

Expand Down
15 changes: 15 additions & 0 deletions impit-python/test/async_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,21 @@ async def test_iter_bytes_without_consumed(self, browser: Browser) -> None:
with pytest.raises(StreamClosed):
_ = response.content

async def test_read_truncated_body_raises_remote_protocol_error(self, browser: Browser) -> None:
port_holder = [0]
thread = threading.Thread(target=truncating_server, args=(port_holder,))
thread.start()
await asyncio.sleep(0.1)

impit = AsyncClient(browser=browser)

async with impit.stream('GET', f'http://localhost:{port_holder[0]}/', timeout=5) as response:
assert response.status_code == 200
with pytest.raises(RemoteProtocolError):
await response.aread()

thread.join()

async def test_truncated_stream_raises(self, browser: Browser) -> None:
port_holder = [0]
thread = threading.Thread(target=truncating_server, args=(port_holder,))
Expand Down
15 changes: 15 additions & 0 deletions impit-python/test/basic_client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,21 @@ def test_truncated_stream_raises(self, browser: Browser) -> None:

thread.join()

def test_read_truncated_body_raises_remote_protocol_error(self, browser: Browser) -> None:
port_holder = [0]
thread = threading.Thread(target=truncating_server, args=(port_holder,))
thread.start()
time.sleep(0.1)

impit = Client(browser=browser)

with impit.stream('GET', f'http://localhost:{port_holder[0]}/', timeout=5) as response:
assert response.status_code == 200
with pytest.raises(RemoteProtocolError):
response.read()

thread.join()


def make_slow_server(port_holder: list[int], delay: float = 2.0) -> None:
"""Start a server in a daemon thread that waits `delay` seconds before responding."""
Expand Down
Loading