test_redirects.py
This file
Path
tests/client/test_redirects.py
374 lines · 13.9 KiB · Python
Last changed by
Dispatcher -> AsyncDispatcher (#725)Tom Christiebefore adoptione19bd9b
History of this fileTake it
The walk stopped after 200 commits: lines older than 4616031 point at it.
Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 1–7why, one step back1import json2from urllib.parse import parse_qs34import pytest56from httpx import (7 URL,Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 8why, one step back8 AsyncClient,Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 9–10why, one step back9 NotRedirectResponse,10 RedirectLoop,Drop sync (#544)Tom Christiebefore adoption206c537
line 11why, one step back11 Request,Repurpose RedirectBodyUnavailable as RequestBodyUnavailable (#690)Florimond Mancabefore adoption910aa90
line 12why, one step back12 RequestBodyUnavailable,Drop sync (#544)Tom Christiebefore adoption206c537
line 13why, one step back13 Response,Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 14–16why, one step back14 TooManyRedirects,15 codes,16)Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 17why, one step back17from httpx.config import CertTypes, TimeoutTypes, VerifyTypesDispatcher -> AsyncDispatcher (#725)Tom Christiebefore adoptione19bd9b
line 18why, one step back18from httpx.dispatch.base import AsyncDispatcherDocument + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 19–20why, one step back1920Dispatcher -> AsyncDispatcher (#725)Tom Christiebefore adoptione19bd9b
line 21why, one step back21class MockDispatch(AsyncDispatcher):Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 22–23why, one step back22 async def send(23 self,Drop sync (#544)Tom Christiebefore adoption206c537
line 24why, one step back24 request: Request,Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 25–27why, one step back25 verify: VerifyTypes = None,26 cert: CertTypes = None,27 timeout: TimeoutTypes = None,Drop sync (#544)Tom Christiebefore adoption206c537
line 28why, one step back28 ) -> Response:Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
line 29why, one step back29 if request.url.path == "/no_redirect":Drop sync (#544)Tom Christiebefore adoption206c537
line 30why, one step back30 return Response(codes.OK, request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 31–34why, one step back3132 elif request.url.path == "/redirect_301":33 status_code = codes.MOVED_PERMANENTLY34 headers = {"location": "https://example.org/"}Drop sync (#544)Tom Christiebefore adoption206c537
line 35why, one step back35 return Response(status_code, headers=headers, request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 36–39why, one step back3637 elif request.url.path == "/redirect_302":38 status_code = codes.FOUND39 headers = {"location": "https://example.org/"}Drop sync (#544)Tom Christiebefore adoption206c537
line 40why, one step back40 return Response(status_code, headers=headers, request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 41–44why, one step back4142 elif request.url.path == "/redirect_303":43 status_code = codes.SEE_OTHER44 headers = {"location": "https://example.org/"}Drop sync (#544)Tom Christiebefore adoption206c537
line 45why, one step back45 return Response(status_code, headers=headers, request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 46–48why, one step back4647 elif request.url.path == "/relative_redirect":48 headers = {"location": "/"}Drop sync (#544)Tom Christiebefore adoption206c537
line 49why, one step back49 return Response(codes.SEE_OTHER, headers=headers, request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 50–52why, one step back5051 elif request.url.path == "/no_scheme_redirect":52 headers = {"location": "//example.org/"}Drop sync (#544)Tom Christiebefore adoption206c537
line 53why, one step back53 return Response(codes.SEE_OTHER, headers=headers, request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 54–63why, one step back5455 elif request.url.path == "/multiple_redirects":56 params = parse_qs(request.url.query)57 count = int(params.get("count", "0")[0])58 redirect_count = count - 159 code = codes.SEE_OTHER if count else codes.OK60 location = "/multiple_redirects"61 if redirect_count:62 location += "?count=" + str(redirect_count)63 headers = {"location": location} if count else {}Drop sync (#544)Tom Christiebefore adoption206c537
line 64why, one step back64 return Response(code, headers=headers, request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 65–67why, one step back6566 if request.url.path == "/redirect_loop":67 headers = {"location": "/redirect_loop"}Drop sync (#544)Tom Christiebefore adoption206c537
line 68why, one step back68 return Response(codes.SEE_OTHER, headers=headers, request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 69–71why, one step back6970 elif request.url.path == "/cross_domain":71 headers = {"location": "https://example.org/cross_domain_target"}Drop sync (#544)Tom Christiebefore adoption206c537
line 72why, one step back72 return Response(codes.SEE_OTHER, headers=headers, request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 73–76why, one step back7374 elif request.url.path == "/cross_domain_target":75 headers = dict(request.headers.items())76 content = json.dumps({"headers": headers}).encode()Drop sync (#544)Tom Christiebefore adoption206c537
line 77why, one step back77 return Response(codes.OK, content=content, request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 78–79why, one step back7879 elif request.url.path == "/redirect_body":Bump coverage (#705)Tom Christiebefore adoptionb8394f1
line 80why, one step back80 body = b"".join([part async for part in request.stream])Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
line 81why, one step back81 headers = {"location": "/redirect_body_target"}Drop sync (#544)Tom Christiebefore adoption206c537
line 82why, one step back82 return Response(codes.PERMANENT_REDIRECT, headers=headers, request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 83–84why, one step back8384 elif request.url.path == "/redirect_no_body":Use Streams API for both requests and responses. (#648)Tom Christiebefore adoptioncee1fcc
line 85why, one step back85 content = b"".join([part async for part in request.stream])Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
line 86why, one step back86 headers = {"location": "/redirect_body_target"}Drop sync (#544)Tom Christiebefore adoption206c537
line 87why, one step back87 return Response(codes.SEE_OTHER, headers=headers, request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 88–89why, one step back8889 elif request.url.path == "/redirect_body_target":Use Streams API for both requests and responses. (#648)Tom Christiebefore adoptioncee1fcc
line 90why, one step back90 content = b"".join([part async for part in request.stream])Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 91–92why, one step back91 headers = dict(request.headers.items())92 body = json.dumps({"body": content.decode(), "headers": headers}).encode()Drop sync (#544)Tom Christiebefore adoption206c537
line 93why, one step back93 return Response(codes.OK, content=body, request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 94–97why, one step back9495 elif request.url.path == "/cross_subdomain":96 if request.headers["host"] != "www.example.org":97 headers = {"location": "https://www.example.org/cross_subdomain"}Drop sync (#544)Tom Christiebefore adoption206c537
line 98why, one step back98 return Response(Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 99–101why, one step back99 codes.PERMANENT_REDIRECT, headers=headers, request=request100 )101 else:Drop sync (#544)Tom Christiebefore adoption206c537
line 102why, one step back102 return Response(codes.OK, content=b"Hello, world!", request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
line 103why, one step back103Drop sync (#544)Tom Christiebefore adoption206c537
line 104why, one step back104 return Response(codes.OK, content=b"Hello, world!", request=request)Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 105–106why, one step back105106Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 107–108why, one step back107@pytest.mark.usefixtures("async_environment")108async def test_no_redirect():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 109why, one step back109 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 110–113why, one step back110 url = "https://example.com/no_redirect"111 response = await client.get(url)112 assert response.status_code == 200113 with pytest.raises(NotRedirectResponse):Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999
line 114why, one step back114 await response.anext()Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 115–116why, one step back115116Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 117–118why, one step back117@pytest.mark.usefixtures("async_environment")118async def test_redirect_301():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 119why, one step back119 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 120–125why, one step back120 response = await client.post("https://example.org/redirect_301")121 assert response.status_code == codes.OK122 assert response.url == URL("https://example.org/")123 assert len(response.history) == 1124125Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 126–127why, one step back126@pytest.mark.usefixtures("async_environment")127async def test_redirect_302():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 128why, one step back128 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 129–134why, one step back129 response = await client.post("https://example.org/redirect_302")130 assert response.status_code == codes.OK131 assert response.url == URL("https://example.org/")132 assert len(response.history) == 1133134Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 135–136why, one step back135@pytest.mark.usefixtures("async_environment")136async def test_redirect_303():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 137why, one step back137 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 138–143why, one step back138 response = await client.get("https://example.org/redirect_303")139 assert response.status_code == codes.OK140 assert response.url == URL("https://example.org/")141 assert len(response.history) == 1142143Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 144–145why, one step back144@pytest.mark.usefixtures("async_environment")145async def test_disallow_redirects():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 146why, one step back146 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 147–154why, one step back147 response = await client.post(148 "https://example.org/redirect_303", allow_redirects=False149 )150 assert response.status_code == codes.SEE_OTHER151 assert response.url == URL("https://example.org/redirect_303")152 assert response.is_redirect is True153 assert len(response.history) == 0154Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999
line 155why, one step back155 response = await response.anext()Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 156–161why, one step back156 assert response.status_code == codes.OK157 assert response.url == URL("https://example.org/")158 assert response.is_redirect is False159 assert len(response.history) == 1160161Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 162–163why, one step back162@pytest.mark.usefixtures("async_environment")163async def test_relative_redirect():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 164why, one step back164 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 165–170why, one step back165 response = await client.get("https://example.org/relative_redirect")166 assert response.status_code == codes.OK167 assert response.url == URL("https://example.org/")168 assert len(response.history) == 1169170Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 171–172why, one step back171@pytest.mark.usefixtures("async_environment")172async def test_no_scheme_redirect():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 173why, one step back173 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 174–179why, one step back174 response = await client.get("https://example.org/no_scheme_redirect")175 assert response.status_code == codes.OK176 assert response.url == URL("https://example.org/")177 assert len(response.history) == 1178179Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 180–181why, one step back180@pytest.mark.usefixtures("async_environment")181async def test_fragment_redirect():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 182why, one step back182 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 183–188why, one step back183 response = await client.get("https://example.org/relative_redirect#fragment")184 assert response.status_code == codes.OK185 assert response.url == URL("https://example.org/#fragment")186 assert len(response.history) == 1187188Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 189–190why, one step back189@pytest.mark.usefixtures("async_environment")190async def test_multiple_redirects():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 191why, one step back191 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 192–205why, one step back192 response = await client.get("https://example.org/multiple_redirects?count=20")193 assert response.status_code == codes.OK194 assert response.url == URL("https://example.org/multiple_redirects")195 assert len(response.history) == 20196 assert response.history[0].url == URL(197 "https://example.org/multiple_redirects?count=20"198 )199 assert response.history[1].url == URL(200 "https://example.org/multiple_redirects?count=19"201 )202 assert len(response.history[0].history) == 0203 assert len(response.history[1].history) == 1204205Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 206–207why, one step back206@pytest.mark.usefixtures("async_environment")207async def test_too_many_redirects():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 208why, one step back208 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 209–212why, one step back209 with pytest.raises(TooManyRedirects):210 await client.get("https://example.org/multiple_redirects?count=21")211212Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 213–214why, one step back213@pytest.mark.usefixtures("async_environment")214async def test_too_many_redirects_calling_next():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 215why, one step back215 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 216–219why, one step back216 url = "https://example.org/multiple_redirects?count=21"217 response = await client.get(url, allow_redirects=False)218 with pytest.raises(TooManyRedirects):219 while response.is_redirect:Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999
line 220why, one step back220 response = await response.anext()Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 221–222why, one step back221222Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 223–224why, one step back223@pytest.mark.usefixtures("async_environment")224async def test_redirect_loop():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 225why, one step back225 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 226–229why, one step back226 with pytest.raises(RedirectLoop):227 await client.get("https://example.org/redirect_loop")228229Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 230–231why, one step back230@pytest.mark.usefixtures("async_environment")231async def test_redirect_loop_calling_next():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 232why, one step back232 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 233–236why, one step back233 url = "https://example.org/redirect_loop"234 response = await client.get(url, allow_redirects=False)235 with pytest.raises(RedirectLoop):236 while response.is_redirect:Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999
line 237why, one step back237 response = await response.anext()Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 238–239why, one step back238239Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 240–241why, one step back240@pytest.mark.usefixtures("async_environment")241async def test_cross_domain_redirect():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 242why, one step back242 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 243–249why, one step back243 url = "https://example.com/cross_domain"244 headers = {"Authorization": "abc"}245 response = await client.get(url, headers=headers)246 assert response.url == URL("https://example.org/cross_domain_target")247 assert "authorization" not in response.json()["headers"]248249Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 250–251why, one step back250@pytest.mark.usefixtures("async_environment")251async def test_same_domain_redirect():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 252why, one step back252 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 253–259why, one step back253 url = "https://example.org/cross_domain"254 headers = {"Authorization": "abc"}255 response = await client.get(url, headers=headers)256 assert response.url == URL("https://example.org/cross_domain_target")257 assert response.json()["headers"]["authorization"] == "abc"258259Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 260–261why, one step back260@pytest.mark.usefixtures("async_environment")261async def test_body_redirect():Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 262–264why, one step back262 """263 A 308 redirect should preserve the request body.264 """Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 265why, one step back265 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 266–273why, one step back266 url = "https://example.org/redirect_body"267 data = b"Example request body"268 response = await client.post(url, data=data)269 assert response.url == URL("https://example.org/redirect_body_target")270 assert response.json()["body"] == "Example request body"271 assert "content-length" in response.json()["headers"]272273Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 274–275why, one step back274@pytest.mark.usefixtures("async_environment")275async def test_no_body_redirect():Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 276–278why, one step back276 """277 A 303 redirect should remove the request body.278 """Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 279why, one step back279 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 280–287why, one step back280 url = "https://example.org/redirect_no_body"281 data = b"Example request body"282 response = await client.post(url, data=data)283 assert response.url == URL("https://example.org/redirect_body_target")284 assert response.json()["body"] == ""285 assert "content-length" not in response.json()["headers"]286287Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 288–289why, one step back288@pytest.mark.usefixtures("async_environment")289async def test_cannot_redirect_streaming_body():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 290why, one step back290 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 291–295why, one step back291 url = "https://example.org/redirect_body"292293 async def streaming_body():294 yield b"Example request body"295Repurpose RedirectBodyUnavailable as RequestBodyUnavailable (#690)Florimond Mancabefore adoption910aa90
line 296why, one step back296 with pytest.raises(RequestBodyUnavailable):Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 297–299why, one step back297 await client.post(url, data=streaming_body())298299Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 300–301why, one step back300@pytest.mark.usefixtures("async_environment")301async def test_cross_subdomain_redirect():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 302why, one step back302 client = AsyncClient(dispatch=MockDispatch())Document + recommend async with syntax for AsyncClient (#344)Florimond Mancabefore adoption4616031
lines 303–305why, one step back303 url = "https://example.com/cross_subdomain"304 response = await client.get(url)305 assert response.url == URL("https://www.example.org/cross_subdomain")Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 306–307why, one step back306307Dispatcher -> AsyncDispatcher (#725)Tom Christiebefore adoptione19bd9b
line 308why, one step back308class MockCookieDispatch(AsyncDispatcher):Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 309–310why, one step back309 async def send(310 self,Drop sync (#544)Tom Christiebefore adoption206c537
line 311why, one step back311 request: Request,Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 312–314why, one step back312 verify: VerifyTypes = None,313 cert: CertTypes = None,314 timeout: TimeoutTypes = None,Drop sync (#544)Tom Christiebefore adoption206c537
line 315why, one step back315 ) -> Response:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 316–320why, one step back316 if request.url.path == "/":317 if "cookie" in request.headers:318 content = b"Logged in"319 else:320 content = b"Not logged in"Drop sync (#544)Tom Christiebefore adoption206c537
line 321why, one step back321 return Response(codes.OK, content=content, request=request)Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 322–332why, one step back322323 elif request.url.path == "/login":324 status_code = codes.SEE_OTHER325 headers = {326 "location": "/",327 "set-cookie": (328 "session=eyJ1c2VybmFtZSI6ICJ0b21; path=/; Max-Age=1209600; "329 "httponly; samesite=lax"330 ),331 }332Drop sync (#544)Tom Christiebefore adoption206c537
line 333why, one step back333 return Response(status_code, headers=headers, request=request)Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 334–343why, one step back334335 elif request.url.path == "/logout":336 status_code = codes.SEE_OTHER337 headers = {338 "location": "/",339 "set-cookie": (340 "session=null; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; "341 "httponly; samesite=lax"342 ),343 }Drop sync (#544)Tom Christiebefore adoption206c537
line 344why, one step back344 return Response(status_code, headers=headers, request=request)Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 345–346why, one step back345346Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 347–348why, one step back347@pytest.mark.usefixtures("async_environment")348async def test_redirect_cookie_behavior():Rename Client to AsyncClient (with compat synonym) (#680)Florimond Mancabefore adoptione284b84
line 349why, one step back349 client = AsyncClient(dispatch=MockCookieDispatch())Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 350–374why, one step back350351 # The client is not logged in.352 response = await client.get("https://example.com/")353 assert response.url == "https://example.com/"354 assert response.text == "Not logged in"355356 # Login redirects to the homepage, setting a session cookie.357 response = await client.post("https://example.com/login")358 assert response.url == "https://example.com/"359 assert response.text == "Logged in"360361 # The client is logged in.362 response = await client.get("https://example.com/")363 assert response.url == "https://example.com/"364 assert response.text == "Logged in"365366 # Logout redirects to the homepage, expiring the session cookie.367 response = await client.post("https://example.com/logout")368 assert response.url == "https://example.com/"369 assert response.text == "Not logged in"370371 # The client is not logged in.372 response = await client.get("https://example.com/")373 assert response.url == "https://example.com/"374 assert response.text == "Not logged in"