Repurpose RedirectBodyUnavailable as RequestBodyUnavailable (#690)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Florimond Manca · committed by GitHub · parent ff44d2d · Browse files · 4 files·+18 added−13 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+18 added−13 removed
- tests:+2 added−2 removed
- other:+16 added−11 removed
Provenance
- Commit
910aa90- Tree
e45ea8d- Author
Florimond Manca <florimond.manca@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
ff44d2d
4 files changed+18 added−13 removed
modified:httpx/__init__.py+2 added-2 removed
15 unmodified lines16 PoolTimeout,17 ProtocolError,18 ProxyError,19 ReadTimeout,20- RedirectBodyUnavailable,20 RedirectLoop,21+ RequestBodyUnavailable,22 ResponseClosed,23 ResponseNotRead,24 StreamConsumed,25 TimeoutException,36 unmodified lines62 "NotRedirectResponse",63 "PoolTimeout",64 "ProtocolError",65 "ReadTimeout",66- "RedirectBodyUnavailable",66 "RedirectLoop",67+ "RequestBodyUnavailable",68 "ResponseClosed",69 "ResponseNotRead",70 "StreamConsumed",71 "ProxyError",13 unmodified linesmodified:httpx/client.py+7 added-2 removed
25 unmodified lines26 from .dispatch.proxy_http import HTTPProxy27 from .exceptions import (28 HTTPError,29 InvalidURL,30- RedirectBodyUnavailable,30 RedirectLoop,31+ RequestBodyUnavailable,32 TooManyRedirects,33 )34 from .models import (35 URL,524 unmodified lines560 Return the body that should be used for the redirect request.561 """562 if method != request.method and method == "GET":563 return None564+565 if not request.stream.can_replay():565- raise RedirectBodyUnavailable()566+ raise RequestBodyUnavailable(567+ "Got a redirect response, but the request body was streaming "568+ "and is no longer available."569+ )570+571 return request.stream572 573 async def send_handling_auth(574 self, request: Request, auth: Auth, timeout: Timeout,392 unmodified linesmodified:httpx/exceptions.py+7 added-7 removed
84 unmodified lines85 Too many redirects.86 """87 88 89-class RedirectBodyUnavailable(RedirectError):90- """91- Got a redirect response, but the request body was streaming, and is92- no longer available.93- """94-95-89 class RedirectLoop(RedirectError):90 """91 Infinite redirect loop.92 """16 unmodified lines109 an invalid way.110 """111 112 113+class RequestBodyUnavailable(StreamError):114+ """115+ Had to send the request again, but the request body was streaming, and is116+ no longer available.117+ """118+119+120 class StreamConsumed(StreamError):121 """122 Attempted to read or stream response content, but the content has already123 been streamed.36 unmodified linesmodified:tests/client/test_redirects.py+2 added-2 removed
5 unmodified lines6 from httpx import (7 URL,8 AsyncClient,9 NotRedirectResponse,10- RedirectBodyUnavailable,10 RedirectLoop,11 Request,12+ RequestBodyUnavailable,13 Response,14 TooManyRedirects,15 codes,16 )275 unmodified lines292 293 async def streaming_body():294 yield b"Example request body"295 296- with pytest.raises(RedirectBodyUnavailable):296+ with pytest.raises(RequestBodyUnavailable):297 await client.post(url, data=streaming_body())298 299 300 @pytest.mark.usefixtures("async_environment")74 unmodified lines