Close WSGI iterable when WSGIByteStream is closed (#1830)
* Make test fail when WSGI iterable is not closed * Close WSGI iterable when WSGIByteStream is closed
This commit is contained in:
parent
ecbece178f
commit
0d3fcc74a5
@ -16,12 +16,17 @@ def _skip_leading_empty_chunks(body: typing.Iterable) -> typing.Iterable:
|
||||
|
||||
class WSGIByteStream(SyncByteStream):
|
||||
def __init__(self, result: typing.Iterable[bytes]) -> None:
|
||||
self._close = getattr(result, "close", None)
|
||||
self._result = _skip_leading_empty_chunks(result)
|
||||
|
||||
def __iter__(self) -> typing.Iterator[bytes]:
|
||||
for part in self._result:
|
||||
yield part
|
||||
|
||||
def close(self) -> None:
|
||||
if self._close is not None:
|
||||
self._close()
|
||||
|
||||
|
||||
class WSGITransport(BaseTransport):
|
||||
"""
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import sys
|
||||
import wsgiref.validate
|
||||
from functools import partial
|
||||
|
||||
import pytest
|
||||
@ -19,7 +20,7 @@ def application_factory(output):
|
||||
for item in output:
|
||||
yield item
|
||||
|
||||
return application
|
||||
return wsgiref.validate.validator(application)
|
||||
|
||||
|
||||
def echo_body(environ, start_response):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user