Skip to content
Myr

Rejig response streaming/closing

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

authored by Tom Christie · committed by Tom Christie · parent ee6f42a · Browse files · 4 files+16 added−18 removed
This commit

State

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

Diff stats

4 files+16 added−18 removed

  • other:+16 added−18 removed

4 files+16 added−18 removed

modified:httpcore/connections.py+5 added-16 removed
38 unmodified lines
39 )40 except asyncio.TimeoutError:41 raise ConnectTimeout()4243 async def send(self, request: Request, stream: bool = False) -> Response:43 async def send(self, request: Request) -> Response:44 method = request.method.encode()45 target = request.url.target46 headers = request.headers47
20 unmodified lines
68 event = await self._receive_event()69 assert isinstance(event, h11.Response)70 status_code = event.status_code71 headers = event.headers72 body = self.body_iter()73 return Response(74 status_code=status_code, headers=headers, body=body, on_close=self.close75 )7673 if stream:74 body_iter = self.body_iter()75 return Response(status_code=status_code, headers=headers, body=body_iter)7677 #  Get the response body.78 body = b""79 event = await self._receive_event()80 while isinstance(event, h11.Data):81 body += event.data82 event = await self._receive_event()83 assert isinstance(event, h11.EndOfMessage)84 await self.close()8586 return Response(status_code=status_code, headers=headers, body=body)8777 async def body_iter(self) -> typing.AsyncIterator[bytes]:78 event = await self._receive_event()79 while isinstance(event, h11.Data):80 yield event.data
32 unmodified lines
modified:httpcore/datastructures.py+4 added
188 unmodified lines
189 yield part190 await self.close()191192 async def close(self) -> None:193 """194 Close the response and release the connection.195 Automatically called if the response body is read to completion.196 """197 if not self.is_closed:198 self.is_closed = True199 if self.on_close is not None:200 await self.on_close()
modified:httpcore/pool.py+6 added-1 removed
41 unmodified lines
42 parsed_url = URL(url)43 request = Request(method, parsed_url, headers=headers, body=body)44 ssl_context = await self.get_ssl_context(parsed_url)45 connection = await self.acquire_connection(parsed_url, ssl=ssl_context)46 response = await connection.send(request, stream=stream)46 response = await connection.send(request)47 if not stream:48 try:49 await response.read()50 finally:51 await response.close()52 return response5354 async def acquire_connection(55 self, url: URL, *, ssl: typing.Union[bool, ssl.SSLContext] = False
76 unmodified lines
modified:setup.py+1 added-1 removed
45 unmodified lines
46 author="Tom Christie",47 author_email="tom@tomchristie.com",48 packages=get_packages("httpcore"),49 data_files=[("", ["LICENSE.md"])],50 install_requires=["h11"],50 install_requires=["h11", "certifi"],51 classifiers=[52 "Development Status :: 3 - Alpha",53 "Environment :: Web Environment",54 "Intended Audience :: Developers",
9 unmodified lines