Repurpose RedirectBodyUnavailable as RequestBodyUnavailable (#690)
This commit is contained in:
parent
ff44d2d1b8
commit
910aa9094c
@ -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",
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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())
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user