From: Florimond Manca Date: Fri, 3 Jan 2020 21:25:55 +0000 (+0100) Subject: Repurpose RedirectBodyUnavailable as RequestBodyUnavailable (#690) X-Git-Tag: 0.11.0~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=910aa9094c4dde3516f38086da30adf52127ba49;p=thirdparty%2Fhttpx.git Repurpose RedirectBodyUnavailable as RequestBodyUnavailable (#690) --- diff --git a/httpx/__init__.py b/httpx/__init__.py index caaa81a9..01f40682 100644 --- a/httpx/__init__.py +++ b/httpx/__init__.py @@ -17,8 +17,8 @@ from .exceptions import ( ProtocolError, ProxyError, ReadTimeout, - RedirectBodyUnavailable, RedirectLoop, + RequestBodyUnavailable, ResponseClosed, ResponseNotRead, StreamConsumed, @@ -63,8 +63,8 @@ __all__ = [ "PoolTimeout", "ProtocolError", "ReadTimeout", - "RedirectBodyUnavailable", "RedirectLoop", + "RequestBodyUnavailable", "ResponseClosed", "ResponseNotRead", "StreamConsumed", diff --git a/httpx/client.py b/httpx/client.py index b2c2e5ee..27a146ae 100644 --- a/httpx/client.py +++ b/httpx/client.py @@ -27,8 +27,8 @@ from .dispatch.proxy_http import HTTPProxy from .exceptions import ( HTTPError, InvalidURL, - RedirectBodyUnavailable, RedirectLoop, + RequestBodyUnavailable, TooManyRedirects, ) from .models import ( @@ -561,8 +561,13 @@ class AsyncClient: """ if method != request.method and method == "GET": return None + if not request.stream.can_replay(): - raise RedirectBodyUnavailable() + raise RequestBodyUnavailable( + "Got a redirect response, but the request body was streaming " + "and is no longer available." + ) + return request.stream async def send_handling_auth( diff --git a/httpx/exceptions.py b/httpx/exceptions.py index 2d8d27dc..e1992708 100644 --- a/httpx/exceptions.py +++ b/httpx/exceptions.py @@ -86,13 +86,6 @@ class TooManyRedirects(RedirectError): """ -class RedirectBodyUnavailable(RedirectError): - """ - Got a redirect response, but the request body was streaming, and is - no longer available. - """ - - class RedirectLoop(RedirectError): """ Infinite redirect loop. @@ -117,6 +110,13 @@ class StreamError(HTTPError): """ +class RequestBodyUnavailable(StreamError): + """ + Had to send the request again, but the request body was streaming, and is + no longer available. + """ + + class StreamConsumed(StreamError): """ Attempted to read or stream response content, but the content has already diff --git a/tests/client/test_redirects.py b/tests/client/test_redirects.py index 663d2def..4c027455 100644 --- a/tests/client/test_redirects.py +++ b/tests/client/test_redirects.py @@ -7,9 +7,9 @@ from httpx import ( URL, AsyncClient, NotRedirectResponse, - RedirectBodyUnavailable, RedirectLoop, Request, + RequestBodyUnavailable, Response, TooManyRedirects, codes, @@ -293,7 +293,7 @@ async def test_cannot_redirect_streaming_body(): async def streaming_body(): yield b"Example request body" - with pytest.raises(RedirectBodyUnavailable): + with pytest.raises(RequestBodyUnavailable): await client.post(url, data=streaming_body())