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:
Stanis Trendelenburg 2021-09-01 17:21:01 +02:00 committed by GitHub
parent ecbece178f
commit 0d3fcc74a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -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):
"""

View File

@ -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):