Skip to content
Myr

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 file

Take 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 back
1import json
2from urllib.parse import parse_qs34import pytest56from httpx import (7 URL,

Drop sync (#544)Tom Christiebefore adoption206c537

line 8why, one step back
8 Client,

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 9–11why, one step back
9 NotRedirectResponse,
10 RedirectBodyUnavailable,11 RedirectLoop,

Drop sync (#544)Tom Christiebefore adoption206c537

lines 12–13why, one step back
12 Request,
13 Response,

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 14–16why, one step back
14 TooManyRedirects,
15 codes,16)

Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b

lines 17–18why, one step back
17from httpx.config import CertTypes, TimeoutTypes, VerifyTypes
18from httpx.dispatch.base import Dispatcher

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 19–20why, one step back
19
20

Drop sync (#544)Tom Christiebefore adoption206c537

line 21why, one step back
21class MockDispatch(Dispatcher):

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 22–23why, one step back
22 async def send(
23 self,

Drop sync (#544)Tom Christiebefore adoption206c537

line 24why, one step back
24 request: Request,

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 25–27why, one step back
25 verify: VerifyTypes = None,
26 cert: CertTypes = None,27 timeout: TimeoutTypes = None,

Drop sync (#544)Tom Christiebefore adoption206c537

line 28why, one step back
28 ) -> Response:

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

line 29why, one step back
29 if request.url.path == "/no_redirect":

Drop sync (#544)Tom Christiebefore adoption206c537

line 30why, one step back
30 return Response(codes.OK, request=request)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 31–34why, one step back
31
32 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 back
35 return Response(status_code, headers=headers, request=request)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 36–39why, one step back
36
37 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 back
40 return Response(status_code, headers=headers, request=request)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 41–44why, one step back
41
42 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 back
45 return Response(status_code, headers=headers, request=request)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 46–48why, one step back
46
47 elif request.url.path == "/relative_redirect":48 headers = {"location": "/"}

Drop sync (#544)Tom Christiebefore adoption206c537

line 49why, one step back
49 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 back
50
51 elif request.url.path == "/no_scheme_redirect":52 headers = {"location": "//example.org/"}

Drop sync (#544)Tom Christiebefore adoption206c537

line 53why, one step back
53 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 back
54
55 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 back
64 return Response(code, headers=headers, request=request)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 65–67why, one step back
65
66 if request.url.path == "/redirect_loop":67 headers = {"location": "/redirect_loop"}

Drop sync (#544)Tom Christiebefore adoption206c537

line 68why, one step back
68 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 back
69
70 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 back
72 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 back
73
74 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 back
77 return Response(codes.OK, content=content, request=request)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 78–80why, one step back
78
79 elif request.url.path == "/redirect_body":80 headers = {"location": "/redirect_body_target"}

Drop sync (#544)Tom Christiebefore adoption206c537

line 81why, one step back
81 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 back
82
83 elif request.url.path == "/redirect_no_body":

Use Streams API for both requests and responses. (#648)Tom Christiebefore adoptioncee1fcc

line 84why, one step back
84 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 back
85 headers = {"location": "/redirect_body_target"}

Drop sync (#544)Tom Christiebefore adoption206c537

line 86why, one step back
86 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 back
87
88 elif request.url.path == "/redirect_body_target":

Use Streams API for both requests and responses. (#648)Tom Christiebefore adoptioncee1fcc

line 89why, one step back
89 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 back
90 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 back
92 return Response(codes.OK, content=body, request=request)

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 93–96why, one step back
93
94 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 back
97 return Response(

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 98–100why, one step back
98 codes.PERMANENT_REDIRECT, headers=headers, request=request
99 )100 else:

Drop sync (#544)Tom Christiebefore adoption206c537

line 101why, one step back
101 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 back
102

Drop sync (#544)Tom Christiebefore adoption206c537

line 103why, one step back
103 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 back
104
105

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 106–107why, one step back
106@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 back
108 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 109–112why, one step back
109 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 back
113 await response.anext()

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 114–115why, one step back
114
115

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 116–117why, one step back
116@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 back
118 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 119–124why, one step back
119 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) == 1123124

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 125–126why, one step back
125@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 back
127 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 128–133why, one step back
128 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) == 1132133

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 134–135why, one step back
134@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 back
136 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 137–142why, one step back
137 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) == 1141142

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 143–144why, one step back
143@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 back
145 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 146–153why, one step back
146 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) == 0153

Rename 'next' to 'anext' on Response (#676)Florimond Mancabefore adoption3462999

line 154why, one step back
154 response = await response.anext()

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 155–160why, one step back
155 assert response.status_code == codes.OK
156 assert response.url == URL("https://example.org/")157 assert response.is_redirect is False158 assert len(response.history) == 1159160

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 161–162why, one step back
161@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 back
163 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 164–169why, one step back
164 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) == 1168169

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 170–171why, one step back
170@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 back
172 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 173–178why, one step back
173 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) == 1177178

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 179–180why, one step back
179@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 back
181 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 182–187why, one step back
182 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) == 1186187

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 188–189why, one step back
188@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 back
190 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 191–204why, one step back
191 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) == 1203204

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 205–206why, one step back
205@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 back
207 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 208–211why, one step back
208 with pytest.raises(TooManyRedirects):
209 await client.get("https://example.org/multiple_redirects?count=21")210211

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 212–213why, one step back
212@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 back
214 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 215–218why, one step back
215 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 back
219 response = await response.anext()

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 220–221why, one step back
220
221

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 222–223why, one step back
222@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 back
224 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 225–228why, one step back
225 with pytest.raises(RedirectLoop):
226 await client.get("https://example.org/redirect_loop")227228

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 229–230why, one step back
229@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 back
231 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 232–235why, one step back
232 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 back
236 response = await response.anext()

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 237–238why, one step back
237
238

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 239–240why, one step back
239@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 back
241 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 242–248why, one step back
242 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"]247248

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 249–250why, one step back
249@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 back
251 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 252–258why, one step back
252 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"257258

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 259–260why, one step back
259@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 back
261 """
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 back
264 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 265–272why, one step back
265 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"]271272

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 273–274why, one step back
273@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 back
275 """
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 back
278 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 279–286why, one step back
279 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"]285286

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 287–288why, one step back
287@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 back
289 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 290–298why, one step back
290 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())297298

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 299–300why, one step back
299@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 back
301 client = Client(dispatch=MockDispatch())

Set Host header when redirecting cross-origin (#321)Gaurav Dhameejabefore adoption3065dd6

lines 302–304why, one step back
302 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 back
305
306

Drop sync (#544)Tom Christiebefore adoption206c537

line 307why, one step back
307class MockCookieDispatch(Dispatcher):

Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0

lines 308–309why, one step back
308 async def send(
309 self,

Drop sync (#544)Tom Christiebefore adoption206c537

line 310why, one step back
310 request: Request,

Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0

lines 311–313why, one step back
311 verify: VerifyTypes = None,
312 cert: CertTypes = None,313 timeout: TimeoutTypes = None,

Drop sync (#544)Tom Christiebefore adoption206c537

line 314why, one step back
314 ) -> Response:

Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0

lines 315–319why, one step back
315 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 back
320 return Response(codes.OK, content=content, request=request)

Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0

lines 321–331why, one step back
321
322 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 }331

Drop sync (#544)Tom Christiebefore adoption206c537

line 332why, one step back
332 return Response(status_code, headers=headers, request=request)

Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0

lines 333–342why, one step back
333
334 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 back
343 return Response(status_code, headers=headers, request=request)

Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0

lines 344–345why, one step back
344
345

Clean up 'backend' fixture (#664)Florimond Mancabefore adoptiond0427be

lines 346–347why, one step back
346@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 back
348 client = Client(dispatch=MockCookieDispatch())

Fix redirect cookie behavior (#529)Tom Christiebefore adoption5aca0c0

lines 349–373why, one step back
349
350 # 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"