from .dispatch.threaded import ThreadedDispatcher
from .dispatch.wsgi import WSGIDispatch
from .exceptions import (
+ HTTPError,
InvalidURL,
RedirectBodyUnavailable,
RedirectLoop,
TooManyRedirects,
- HTTPError,
)
from .interfaces import AsyncDispatcher, ConcurrencyBackend, Dispatcher
from .models import (
headers = Headers(request.headers)
if url.origin != request.url.origin:
del headers["Authorization"]
+ del headers["host"]
return headers
def redirect_content(
Base class for Httpx exception
"""
- def __init__(self, request: 'BaseRequest' = None, response: 'BaseResponse' = None, *args) -> None:
+ def __init__(
+ self, request: "BaseRequest" = None, response: "BaseResponse" = None, *args
+ ) -> None:
self.response = response
self.request = request or getattr(self.response, "request", None)
super().__init__(*args)
body = json.dumps({"body": content.decode()}).encode()
return AsyncResponse(codes.OK, content=body, request=request)
+ elif request.url.path == "/cross_subdomain":
+ if request.headers["host"] != "www.example.org":
+ headers = {"location": "https://www.example.org/cross_subdomain"}
+ return AsyncResponse(
+ codes.PERMANENT_REDIRECT, headers=headers, request=request
+ )
+ else:
+ return AsyncResponse(
+ codes.OK, content=b"Hello, world!", request=request
+ )
+
return AsyncResponse(codes.OK, content=b"Hello, world!", request=request)
with pytest.raises(RedirectBodyUnavailable):
await client.post(url, data=streaming_body())
+
+
+@pytest.mark.asyncio
+async def test_cross_dubdomain_redirect():
+ client = AsyncClient(dispatch=MockDispatch())
+ url = "https://example.com/cross_subdomain"
+ response = await client.get(url)
+ assert response.url == URL("https://www.example.org/cross_subdomain")