Skip to content
Myr

Close WSGI iterable when WSGIByteStream is closed (#1830)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Make test fail when WSGI iterable is not closed * Close WSGI iterable when WSGIByteStream is closed

authored by Stanis Trendelenburg · committed by GitHub · parent ecbece1 · Browse files · 2 files+7 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+7 added−1 removed

  • tests:+2 added−1 removed
  • other:+5 added−0 removed

2 files+7 added−1 removed

modified:httpx/_transports/wsgi.py+5 added
14 unmodified lines
151617class WSGIByteStream(SyncByteStream):18 def __init__(self, result: typing.Iterable[bytes]) -> None:19 self._close = getattr(result, "close", None)20 self._result = _skip_leading_empty_chunks(result)2122 def __iter__(self) -> typing.Iterator[bytes]:23 for part in self._result:24 yield part2526 def close(self) -> None:27 if self._close is not None:28 self._close()293031class WSGITransport(BaseTransport):32 """33 A custom transport that handles sending requests directly to an WSGI app.34 The simplest way to use this functionality is to use the `app` argument.
109 unmodified lines
modified:tests/test_wsgi.py+2 added-1 removed
1import sys2import wsgiref.validate3from functools import partial45import pytest6
12 unmodified lines
1920 for item in output:21 yield item2222 return application23 return wsgiref.validate.validator(application)242526def echo_body(environ, start_response):27 status = "200 OK"
119 unmodified lines