Repurpose RedirectBodyUnavailable as RequestBodyUnavailable (#690)

This commit is contained in:
Florimond Manca 2020-01-03 22:25:55 +01:00 committed by GitHub
parent ff44d2d1b8
commit 910aa9094c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 13 deletions

View File

@ -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",

View File

@ -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(

View File

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

View File

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