test_redirects.py
This file
Path
tests/client/test_redirects.py
373 lines · 13.7 KiB · Python
Last changed by
Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999
History of this fileTake it
The walk stopped after 200 commits: lines older than 3065dd6 point at it.
Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 1–7why, one step back1import json2from urllib.parse import parse_qs34import pytest56from httpx import (7 URL,Drop sync (#544)Tom Christiebefore adoption206c537
line 8why, one step back8 Client,Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 9–11why, one step back9 NotRedirectResponse,10 RedirectBodyUnavailable,11 RedirectLoop,Drop sync (#544)Tom Christiebefore adoption206c537
lines 12–13why, one step back12 Request,13 Response,Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 14–16why, one step back14 TooManyRedirects,15 codes,16)Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
lines 17–18why, one step back17from httpx.config import CertTypes, TimeoutTypes, VerifyTypes18from httpx.dispatch.base import DispatcherSet Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 19–20why, one step back1920Drop sync (#544)Tom Christiebefore adoption206c537
line 21why, one step back21class MockDispatch(Dispatcher):Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 22–23why, one step back22 async def send(23 self,Drop sync (#544)Tom Christiebefore adoption206c537
line 24why, one step back24 request: Request,Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
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:Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
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)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
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)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
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)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
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)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
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)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
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)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
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)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
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)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
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)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
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)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 78–80why, one step back7879 elif request.url.path == "/redirect_body":80 headers = {"location": "/redirect_body_target"}Drop sync (#544)Tom Christiebefore adoption206c537
line 81why, one step back81 return Response(codes.PERMANENT_REDIRECT, headers=headers, request=request)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 82–83why, one step back8283 elif request.url.path == "/redirect_no_body":Use Streams API for both requests and responses. (#648)Tom Christiebefore adoptioncee1fcc
line 84why, one step back84 content = b"".join([part async for part in request.stream])Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
line 85why, one step back85 headers = {"location": "/redirect_body_target"}Drop sync (#544)Tom Christiebefore adoption206c537
line 86why, one step back86 return Response(codes.SEE_OTHER, headers=headers, request=request)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 87–88why, one step back8788 elif request.url.path == "/redirect_body_target":Use Streams API for both requests and responses. (#648)Tom Christiebefore adoptioncee1fcc
line 89why, one step back89 content = b"".join([part async for part in request.stream])Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 90–91why, one step back90 headers = dict(request.headers.items())91 body = json.dumps({"body": content.decode(), "headers": headers}).encode()Drop sync (#544)Tom Christiebefore adoption206c537
line 92why, one step back92 return Response(codes.OK, content=body, request=request)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 93–96why, one step back9394 elif request.url.path == "/cross_subdomain":95 if request.headers["host"] != "www.example.org":96 headers = {"location": "https://www.example.org/cross_subdomain"}Drop sync (#544)Tom Christiebefore adoption206c537
line 97why, one step back97 return Response(Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 98–100why, one step back98 codes.PERMANENT_REDIRECT, headers=headers, request=request99 )100 else:Drop sync (#544)Tom Christiebefore adoption206c537
line 101why, one step back101 return Response(codes.OK, content=b"Hello, world!", request=request)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
line 102why, one step back102Drop sync (#544)Tom Christiebefore adoption206c537
line 103why, one step back103 return Response(codes.OK, content=b"Hello, world!", request=request)Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 104–105why, one step back104105Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 106–107why, one step back106@pytest.mark.usefixtures("async_environment")107async def test_no_redirect():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 108why, one step back108 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 109–112why, one step back109 url = "https://example.com/no_redirect"110 response = await client.get(url)111 assert response.status_code == 200112 with pytest.raises(NotRedirectResponse):Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999
line 113why, one step back113 await response.anext()Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 114–115why, one step back114115Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 116–117why, one step back116@pytest.mark.usefixtures("async_environment")117async def test_redirect_301():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 118why, one step back118 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 119–124why, one step back119 response = await client.post("https://example.org/redirect_301")120 assert response.status_code == codes.OK121 assert response.url == URL("https://example.org/")122 assert len(response.history) == 1123124Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 125–126why, one step back125@pytest.mark.usefixtures("async_environment")126async def test_redirect_302():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 127why, one step back127 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 128–133why, one step back128 response = await client.post("https://example.org/redirect_302")129 assert response.status_code == codes.OK130 assert response.url == URL("https://example.org/")131 assert len(response.history) == 1132133Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 134–135why, one step back134@pytest.mark.usefixtures("async_environment")135async def test_redirect_303():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 136why, one step back136 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 137–142why, one step back137 response = await client.get("https://example.org/redirect_303")138 assert response.status_code == codes.OK139 assert response.url == URL("https://example.org/")140 assert len(response.history) == 1141142Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 143–144why, one step back143@pytest.mark.usefixtures("async_environment")144async def test_disallow_redirects():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 145why, one step back145 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 146–153why, one step back146 response = await client.post(147 "https://example.org/redirect_303", allow_redirects=False148 )149 assert response.status_code == codes.SEE_OTHER150 assert response.url == URL("https://example.org/redirect_303")151 assert response.is_redirect is True152 assert len(response.history) == 0153Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999
line 154why, one step back154 response = await response.anext()Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 155–160why, one step back155 assert response.status_code == codes.OK156 assert response.url == URL("https://example.org/")157 assert response.is_redirect is False158 assert len(response.history) == 1159160Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 161–162why, one step back161@pytest.mark.usefixtures("async_environment")162async def test_relative_redirect():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 163why, one step back163 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 164–169why, one step back164 response = await client.get("https://example.org/relative_redirect")165 assert response.status_code == codes.OK166 assert response.url == URL("https://example.org/")167 assert len(response.history) == 1168169Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 170–171why, one step back170@pytest.mark.usefixtures("async_environment")171async def test_no_scheme_redirect():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 172why, one step back172 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 173–178why, one step back173 response = await client.get("https://example.org/no_scheme_redirect")174 assert response.status_code == codes.OK175 assert response.url == URL("https://example.org/")176 assert len(response.history) == 1177178Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 179–180why, one step back179@pytest.mark.usefixtures("async_environment")180async def test_fragment_redirect():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 181why, one step back181 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 182–187why, one step back182 response = await client.get("https://example.org/relative_redirect#fragment")183 assert response.status_code == codes.OK184 assert response.url == URL("https://example.org/#fragment")185 assert len(response.history) == 1186187Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 188–189why, one step back188@pytest.mark.usefixtures("async_environment")189async def test_multiple_redirects():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 190why, one step back190 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 191–204why, one step back191 response = await client.get("https://example.org/multiple_redirects?count=20")192 assert response.status_code == codes.OK193 assert response.url == URL("https://example.org/multiple_redirects")194 assert len(response.history) == 20195 assert response.history[0].url == URL(196 "https://example.org/multiple_redirects?count=20"197 )198 assert response.history[1].url == URL(199 "https://example.org/multiple_redirects?count=19"200 )201 assert len(response.history[0].history) == 0202 assert len(response.history[1].history) == 1203204Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 205–206why, one step back205@pytest.mark.usefixtures("async_environment")206async def test_too_many_redirects():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 207why, one step back207 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 208–211why, one step back208 with pytest.raises(TooManyRedirects):209 await client.get("https://example.org/multiple_redirects?count=21")210211Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 212–213why, one step back212@pytest.mark.usefixtures("async_environment")213async def test_too_many_redirects_calling_next():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 214why, one step back214 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 215–218why, one step back215 url = "https://example.org/multiple_redirects?count=21"216 response = await client.get(url, allow_redirects=False)217 with pytest.raises(TooManyRedirects):218 while response.is_redirect:Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999
line 219why, one step back219 response = await response.anext()Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 220–221why, one step back220221Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 222–223why, one step back222@pytest.mark.usefixtures("async_environment")223async def test_redirect_loop():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 224why, one step back224 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 225–228why, one step back225 with pytest.raises(RedirectLoop):226 await client.get("https://example.org/redirect_loop")227228Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 229–230why, one step back229@pytest.mark.usefixtures("async_environment")230async def test_redirect_loop_calling_next():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 231why, one step back231 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 232–235why, one step back232 url = "https://example.org/redirect_loop"233 response = await client.get(url, allow_redirects=False)234 with pytest.raises(RedirectLoop):235 while response.is_redirect:Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999
line 236why, one step back236 response = await response.anext()Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 237–238why, one step back237238Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 239–240why, one step back239@pytest.mark.usefixtures("async_environment")240async def test_cross_domain_redirect():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 241why, one step back241 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 242–248why, one step back242 url = "https://example.com/cross_domain"243 headers = {"Authorization": "abc"}244 response = await client.get(url, headers=headers)245 assert response.url == URL("https://example.org/cross_domain_target")246 assert "authorization" not in response.json()["headers"]247248Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 249–250why, one step back249@pytest.mark.usefixtures("async_environment")250async def test_same_domain_redirect():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 251why, one step back251 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 252–258why, one step back252 url = "https://example.org/cross_domain"253 headers = {"Authorization": "abc"}254 response = await client.get(url, headers=headers)255 assert response.url == URL("https://example.org/cross_domain_target")256 assert response.json()["headers"]["authorization"] == "abc"257258Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 259–260why, one step back259@pytest.mark.usefixtures("async_environment")260async def test_body_redirect():Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 261–263why, one step back261 """262 A 308 redirect should preserve the request body.263 """Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 264why, one step back264 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 265–272why, one step back265 url = "https://example.org/redirect_body"266 data = b"Example request body"267 response = await client.post(url, data=data)268 assert response.url == URL("https://example.org/redirect_body_target")269 assert response.json()["body"] == "Example request body"270 assert "content-length" in response.json()["headers"]271272Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 273–274why, one step back273@pytest.mark.usefixtures("async_environment")274async def test_no_body_redirect():Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 275–277why, one step back275 """276 A 303 redirect should remove the request body.277 """Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 278why, one step back278 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 279–286why, one step back279 url = "https://example.org/redirect_no_body"280 data = b"Example request body"281 response = await client.post(url, data=data)282 assert response.url == URL("https://example.org/redirect_body_target")283 assert response.json()["body"] == ""284 assert "content-length" not in response.json()["headers"]285286Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 287–288why, one step back287@pytest.mark.usefixtures("async_environment")288async def test_cannot_redirect_streaming_body():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 289why, one step back289 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 290–298why, one step back290 url = "https://example.org/redirect_body"291292 async def streaming_body():293 yield b"Example request body"294295 with pytest.raises(RedirectBodyUnavailable):296 await client.post(url, data=streaming_body())297298Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 299–300why, one step back299@pytest.mark.usefixtures("async_environment")300async def test_cross_subdomain_redirect():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 301why, one step back301 client = Client(dispatch=MockDispatch())Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6
lines 302–304why, one step back302 url = "https://example.com/cross_subdomain"303 response = await client.get(url)304 assert response.url == URL("https://www.example.org/cross_subdomain")Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 305–306why, one step back305306Drop sync (#544)Tom Christiebefore adoption206c537
line 307why, one step back307class MockCookieDispatch(Dispatcher):Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 308–309why, one step back308 async def send(309 self,Drop sync (#544)Tom Christiebefore adoption206c537
line 310why, one step back310 request: Request,Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 311–313why, one step back311 verify: VerifyTypes = None,312 cert: CertTypes = None,313 timeout: TimeoutTypes = None,Drop sync (#544)Tom Christiebefore adoption206c537
line 314why, one step back314 ) -> Response:Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 315–319why, one step back315 if request.url.path == "/":316 if "cookie" in request.headers:317 content = b"Logged in"318 else:319 content = b"Not logged in"Drop sync (#544)Tom Christiebefore adoption206c537
line 320why, one step back320 return Response(codes.OK, content=content, request=request)Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 321–331why, one step back321322 elif request.url.path == "/login":323 status_code = codes.SEE_OTHER324 headers = {325 "location": "/",326 "set-cookie": (327 "session=eyJ1c2VybmFtZSI6ICJ0b21; path=/; Max-Age=1209600; "328 "httponly; samesite=lax"329 ),330 }331Drop sync (#544)Tom Christiebefore adoption206c537
line 332why, one step back332 return Response(status_code, headers=headers, request=request)Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 333–342why, one step back333334 elif request.url.path == "/logout":335 status_code = codes.SEE_OTHER336 headers = {337 "location": "/",338 "set-cookie": (339 "session=null; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; "340 "httponly; samesite=lax"341 ),342 }Drop sync (#544)Tom Christiebefore adoption206c537
line 343why, one step back343 return Response(status_code, headers=headers, request=request)Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 344–345why, one step back344345Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be
lines 346–347why, one step back346@pytest.mark.usefixtures("async_environment")347async def test_redirect_cookie_behavior():Refactor tests in the light of backend auto-detection (#615)Florimond Mancabefore adoptionab41a5d
line 348why, one step back348 client = Client(dispatch=MockCookieDispatch())Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0
lines 349–373why, one step back349350 # The client is not logged in.351 response = await client.get("https://example.com/")352 assert response.url == "https://example.com/"353 assert response.text == "Not logged in"354355 # Login redirects to the homepage, setting a session cookie.356 response = await client.post("https://example.com/login")357 assert response.url == "https://example.com/"358 assert response.text == "Logged in"359360 # The client is logged in.361 response = await client.get("https://example.com/")362 assert response.url == "https://example.com/"363 assert response.text == "Logged in"364365 # Logout redirects to the homepage, expiring the session cookie.366 response = await client.post("https://example.com/logout")367 assert response.url == "https://example.com/"368 assert response.text == "Not logged in"369370 # The client is not logged in.371 response = await client.get("https://example.com/")372 assert response.url == "https://example.com/"373 assert response.text == "Not logged in"