Close redirect responses (#88)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tom Christie · committed by GitHub · parent d5d726f · Browse files · 1 file·+28 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+28 added−23 removed
- other:+28 added−23 removed
Provenance
- Commit
3ca9a74- Tree
fbd84d3- Author
Tom Christie <tom@tomchristie.com>- Committer
GitHub <noreply@github.com>- Parent
d5d726f
1 file changed+28 added−23 removed
modified:http3/client.py+28 added-23 removed
142 unmodified lines143 144 response = await self.dispatch.send(145 request, verify=verify, cert=cert, timeout=timeout146 )147- assert isinstance(response, AsyncResponse)148- response.history = list(history)149- self.cookies.extract_cookies(response)150- history = [response] + history151- if not response.is_redirect:152- break147+ should_close_response = True148+ try:149+ assert isinstance(response, AsyncResponse)150+ response.history = list(history)151+ self.cookies.extract_cookies(response)152+ history = [response] + history153 154- if allow_redirects:155- request = self.build_redirect_request(request, response)156- else:157-158- async def send_next() -> AsyncResponse:159- nonlocal request, response, verify, cert, allow_redirects, timeout, history154+ if allow_redirects and response.is_redirect:155 request = self.build_redirect_request(request, response)161- response = await self.send_handling_redirects(162- request,163- allow_redirects=allow_redirects,164- verify=verify,165- cert=cert,166- timeout=timeout,167- history=history,168- )169- return response156+ else:157+ should_close_response = False158+ break159+ finally:160+ if should_close_response:161+ await response.close()162 171- response.next = send_next # type: ignore172- break163+ if response.is_redirect:164+ async def send_next() -> AsyncResponse:165+ nonlocal request, response, verify, cert, allow_redirects, timeout, history166+ request = self.build_redirect_request(request, response)167+ response = await self.send_handling_redirects(168+ request,169+ allow_redirects=allow_redirects,170+ verify=verify,171+ cert=cert,172+ timeout=timeout,173+ history=history,174+ )175+ return response176 177+ response.next = send_next # type: ignore178+179 return response180 181 def build_redirect_request(182 self, request: AsyncRequest, response: AsyncResponse654 unmodified lines