test_redirects.py
This file
Path
tests/client/test_redirects.py
416 lines · 15.4 KiB · Python
Last changed by
Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9
History of this fileTake it
The walk stopped after 200 commits: lines older than 225f1e2 point at it.
Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 1–3why, one step back1import httpcore2import pytest3Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 4why, one step back4import httpxVersion 0.15.0 (#1301)Tom Christiebefore adoptionf932af9
line 5why, one step back5from tests.utils import MockTransportUse URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 6–7why, one step back67Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 8–12why, one step back8def redirects(request: httpx.Request) -> httpx.Response:9 if request.url.scheme not in ("http", "https"):10 raise httpcore.UnsupportedProtocol(11 f"Scheme {request.url.scheme!r} not supported."12 )Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 13why, one step back13Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 14–15why, one step back14 if request.url.path == "/no_redirect":15 return httpx.Response(200)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 16why, one step back16Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 17–21why, one step back17 elif request.url.path == "/redirect_301":18 status_code = httpx.codes.MOVED_PERMANENTLY19 content = b"<a href='https://example.org/'>here</a>"20 headers = {"location": "https://example.org/"}21 return httpx.Response(status_code, headers=headers, content=content)Update to httpcore 0.10 (#1126)Tom Christiebefore adoption876e722
line 22why, one step back22Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 23–26why, one step back23 elif request.url.path == "/redirect_302":24 status_code = httpx.codes.FOUND25 headers = {"location": "https://example.org/"}26 return httpx.Response(status_code, headers=headers)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 27why, one step back27Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 28–31why, one step back28 elif request.url.path == "/redirect_303":29 status_code = httpx.codes.SEE_OTHER30 headers = {"location": "https://example.org/"}31 return httpx.Response(status_code, headers=headers)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 32why, one step back32Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 33–36why, one step back33 elif request.url.path == "/relative_redirect":34 status_code = httpx.codes.SEE_OTHER35 headers = {"location": "/"}36 return httpx.Response(status_code, headers=headers)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 37why, one step back37Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 38–41why, one step back38 elif request.url.path == "/malformed_redirect":39 status_code = httpx.codes.SEE_OTHER40 headers = {"location": "https://:443/"}41 return httpx.Response(status_code, headers=headers)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 42why, one step back42Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 43–46why, one step back43 elif request.url.path == "/invalid_redirect":44 status_code = httpx.codes.SEE_OTHER45 raw_headers = [(b"location", "https://😇/".encode("utf-8"))]46 return httpx.Response(status_code, headers=raw_headers)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 47why, one step back47Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 48–51why, one step back48 elif request.url.path == "/no_scheme_redirect":49 status_code = httpx.codes.SEE_OTHER50 headers = {"location": "//example.org/"}51 return httpx.Response(status_code, headers=headers)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 52why, one step back52Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 53–59why, one step back53 elif request.url.path == "/multiple_redirects":54 params = httpx.QueryParams(request.url.query)55 count = int(params.get("count", "0"))56 redirect_count = count - 157 status_code = httpx.codes.SEE_OTHER if count else httpx.codes.OK58 if count:59 location = "/multiple_redirects"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 60why, one step back60 if redirect_count:Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 61–65why, one step back61 location += f"?count={redirect_count}"62 headers = {"location": location}63 else:64 headers = {}65 return httpx.Response(status_code, headers=headers)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 66why, one step back66Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 67–70why, one step back67 if request.url.path == "/redirect_loop":68 status_code = httpx.codes.SEE_OTHER69 headers = {"location": "/redirect_loop"}70 return httpx.Response(status_code, headers=headers)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 71why, one step back71Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 72–75why, one step back72 elif request.url.path == "/cross_domain":73 status_code = httpx.codes.SEE_OTHER74 headers = {"location": "https://example.org/cross_domain_target"}75 return httpx.Response(status_code, headers=headers)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 76why, one step back76Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 77–78why, one step back77 elif request.url.path == "/cross_domain_target":78 status_code = httpx.codes.OKSupport Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941
lines 79–83why, one step back79 data = {80 "body": request.content.decode("ascii"),81 "headers": dict(request.headers),82 }83 return httpx.Response(status_code, json=data)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 84why, one step back84Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 85–88why, one step back85 elif request.url.path == "/redirect_body":86 status_code = httpx.codes.PERMANENT_REDIRECT87 headers = {"location": "/redirect_body_target"}88 return httpx.Response(status_code, headers=headers)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 89why, one step back89Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 90–93why, one step back90 elif request.url.path == "/redirect_no_body":91 status_code = httpx.codes.SEE_OTHER92 headers = {"location": "/redirect_body_target"}93 return httpx.Response(status_code, headers=headers)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 94why, one step back94Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 95why, one step back95 elif request.url.path == "/redirect_body_target":Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941
lines 96–100why, one step back96 data = {97 "body": request.content.decode("ascii"),98 "headers": dict(request.headers),99 }100 return httpx.Response(200, json=data)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 101why, one step back101Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 102–107why, one step back102 elif request.url.path == "/cross_subdomain":103 if request.headers["Host"] != "www.example.org":104 status_code = httpx.codes.PERMANENT_REDIRECT105 headers = {"location": "https://www.example.org/cross_subdomain"}106 return httpx.Response(status_code, headers=headers)107 else:Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941
line 108why, one step back108 return httpx.Response(200, text="Hello, world!")Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 109why, one step back109Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 110–113why, one step back110 elif request.url.path == "/redirect_custom_scheme":111 status_code = httpx.codes.MOVED_PERMANENTLY112 headers = {"location": "market://details?id=42"}113 return httpx.Response(status_code, headers=headers)Improve error when redirecting with custom schemes (#1002)Josep Cugatbefore adoption093cb42
line 114why, one step back114Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 115–116why, one step back115 if request.method == "HEAD":116 return httpx.Response(200)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 117why, one step back117Support Response(text=...), Response(html=...), Response(json=...) (#1297)Tom Christiebefore adoptionf3c2941
line 118why, one step back118 return httpx.Response(200, html="<html><body>Hello, world!</body></html>")Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 119why, one step back119Add test for HEAD redirect behavior (#1184)Florimond Mancabefore adoption09c3e90
line 120why, one step back120Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 121why, one step back121def test_no_redirect():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 122why, one step back122 client = httpx.Client(transport=MockTransport(redirects))Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 123why, one step back123 url = "https://example.com/no_redirect"Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 124why, one step back124 response = client.get(url)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 125why, one step back125 assert response.status_code == 200Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 126–127why, one step back126 with pytest.raises(httpx.NotRedirectResponse):127 response.next()Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 128–129why, one step back128129Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 130why, one step back130def test_redirect_301():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 131why, one step back131 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 132–133why, one step back132 response = client.post("https://example.org/redirect_301")133 assert response.status_code == httpx.codes.OKReplace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 134why, one step back134 assert response.url == "https://example.org/"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 135–137why, one step back135 assert len(response.history) == 1136137Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 138why, one step back138def test_redirect_302():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 139why, one step back139 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 140–141why, one step back140 response = client.post("https://example.org/redirect_302")141 assert response.status_code == httpx.codes.OKReplace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 142why, one step back142 assert response.url == "https://example.org/"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 143–145why, one step back143 assert len(response.history) == 1144145Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 146why, one step back146def test_redirect_303():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 147why, one step back147 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 148–149why, one step back148 response = client.get("https://example.org/redirect_303")149 assert response.status_code == httpx.codes.OKReplace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 150why, one step back150 assert response.url == "https://example.org/"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 151–153why, one step back151 assert len(response.history) == 1152153Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 154why, one step back154def test_disallow_redirects():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 155why, one step back155 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 156–157why, one step back156 response = client.post("https://example.org/redirect_303", allow_redirects=False)157 assert response.status_code == httpx.codes.SEE_OTHERReplace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 158why, one step back158 assert response.url == "https://example.org/redirect_303"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 159–161why, one step back159 assert response.is_redirect is True160 assert len(response.history) == 0161Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 162–163why, one step back162 response = response.next()163 assert response.status_code == httpx.codes.OKReplace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 164why, one step back164 assert response.url == "https://example.org/"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 165–166why, one step back165 assert response.is_redirect is False166 assert len(response.history) == 1Add test for HEAD redirect behavior (#1184)Florimond Mancabefore adoption09c3e90
lines 167–168why, one step back167168Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 169why, one step back169def test_head_redirect():Add test for HEAD redirect behavior (#1184)Florimond Mancabefore adoption09c3e90
lines 170–172why, one step back170 """171 Contrary to Requests, redirects remain enabled by default for HEAD requests.172 """Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 173why, one step back173 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 174–175why, one step back174 response = client.head("https://example.org/redirect_302")175 assert response.status_code == httpx.codes.OKReplace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 176why, one step back176 assert response.url == "https://example.org/"Add test for HEAD redirect behavior (#1184)Florimond Mancabefore adoption09c3e90
lines 177–179why, one step back177 assert response.request.method == "HEAD"178 assert len(response.history) == 1179 assert response.text == ""Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 180–181why, one step back180181Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 182why, one step back182def test_relative_redirect():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 183why, one step back183 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 184–185why, one step back184 response = client.get("https://example.org/relative_redirect")185 assert response.status_code == httpx.codes.OKReplace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 186why, one step back186 assert response.url == "https://example.org/"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 187–189why, one step back187 assert len(response.history) == 1188189Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 190why, one step back190def test_malformed_redirect():Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 191why, one step back191 # https://github.com/encode/httpx/issues/771Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 192why, one step back192 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 193–194why, one step back193 response = client.get("http://example.org/malformed_redirect")194 assert response.status_code == httpx.codes.OKReplace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 195why, one step back195 assert response.url == "https://example.org:443/"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 196why, one step back196 assert len(response.history) == 1Map rfc3986 exceptions (#1163)Joebefore adoption45de714
lines 197–198why, one step back197198Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 199why, one step back199def test_invalid_redirect():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 200why, one step back200 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 201–202why, one step back201 with pytest.raises(httpx.RemoteProtocolError):202 client.get("http://example.org/invalid_redirect")Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 203–204why, one step back203204Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 205why, one step back205def test_no_scheme_redirect():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 206why, one step back206 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 207–208why, one step back207 response = client.get("https://example.org/no_scheme_redirect")208 assert response.status_code == httpx.codes.OKReplace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 209why, one step back209 assert response.url == "https://example.org/"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 210–212why, one step back210 assert len(response.history) == 1211212Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 213why, one step back213def test_fragment_redirect():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 214why, one step back214 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 215–216why, one step back215 response = client.get("https://example.org/relative_redirect#fragment")216 assert response.status_code == httpx.codes.OKReplace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 217why, one step back217 assert response.url == "https://example.org/#fragment"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 218–220why, one step back218 assert len(response.history) == 1219220Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 221why, one step back221def test_multiple_redirects():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 222why, one step back222 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 223–224why, one step back223 response = client.get("https://example.org/multiple_redirects?count=20")224 assert response.status_code == httpx.codes.OKReplace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 225why, one step back225 assert response.url == "https://example.org/multiple_redirects"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 226why, one step back226 assert len(response.history) == 20Replace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
lines 227–228why, one step back227 assert response.history[0].url == "https://example.org/multiple_redirects?count=20"228 assert response.history[1].url == "https://example.org/multiple_redirects?count=19"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 229–233why, one step back229 assert len(response.history[0].history) == 0230 assert len(response.history[1].history) == 1231232233@pytest.mark.usefixtures("async_environment")Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067
line 234why, one step back234async def test_async_too_many_redirects():Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9
line 235why, one step back235 async with httpx.AsyncClient(transport=MockTransport(redirects)) as client:Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 236–237why, one step back236 with pytest.raises(httpx.TooManyRedirects):237 await client.get("https://example.org/multiple_redirects?count=21")Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 238–240why, one step back238239240@pytest.mark.usefixtures("async_environment")Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067
line 241why, one step back241async def test_async_too_many_redirects_calling_next():Version 0.15.0 (#1301)Tom Christiebefore adoptionf932af9
line 242why, one step back242 async with httpx.AsyncClient(transport=MockTransport(redirects)) as client:Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 243–247why, one step back243 url = "https://example.org/multiple_redirects?count=21"244 response = await client.get(url, allow_redirects=False)245 with pytest.raises(httpx.TooManyRedirects):246 while response.is_redirect:247 response = await response.anext()Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 248–249why, one step back248249Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067
line 250why, one step back250def test_sync_too_many_redirects():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 251why, one step back251 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 252why, one step back252 with pytest.raises(httpx.TooManyRedirects):Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067
lines 253–256why, one step back253 client.get("https://example.org/multiple_redirects?count=21")254255256def test_sync_too_many_redirects_calling_next():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 257why, one step back257 client = httpx.Client(transport=MockTransport(redirects))Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067
lines 258–259why, one step back258 url = "https://example.org/multiple_redirects?count=21"259 response = client.get(url, allow_redirects=False)Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 260why, one step back260 with pytest.raises(httpx.TooManyRedirects):Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067
line 261why, one step back261 while response.is_redirect:Add missing `Response.next()` (#1055)Florimond Mancabefore adoption3230cb3
line 262why, one step back262 response = response.next()Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067
lines 263–264why, one step back263264Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 265why, one step back265def test_redirect_loop():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 266why, one step back266 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 267–268why, one step back267 with pytest.raises(httpx.TooManyRedirects):268 client.get("https://example.org/redirect_loop")Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 269–270why, one step back269270Swap auth/redirects ordering (#1267)Tom Christiebefore adoption4d950e5
line 271why, one step back271def test_cross_domain_redirect_with_auth_header():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 272why, one step back272 client = httpx.Client(transport=MockTransport(redirects))Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 273–274why, one step back273 url = "https://example.com/cross_domain"274 headers = {"Authorization": "abc"}Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 275why, one step back275 response = client.get(url, headers=headers)Swap auth/redirects ordering (#1267)Tom Christiebefore adoption4d950e5
lines 276–280why, one step back276 assert response.url == "https://example.org/cross_domain_target"277 assert "authorization" not in response.json()["headers"]278279280def test_cross_domain_redirect_with_auth():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 281why, one step back281 client = httpx.Client(transport=MockTransport(redirects))Swap auth/redirects ordering (#1267)Tom Christiebefore adoption4d950e5
lines 282–283why, one step back282 url = "https://example.com/cross_domain"283 response = client.get(url, auth=("user", "pass"))Replace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 284why, one step back284 assert response.url == "https://example.org/cross_domain_target"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 285–287why, one step back285 assert "authorization" not in response.json()["headers"]286287Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 288why, one step back288def test_same_domain_redirect():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 289why, one step back289 client = httpx.Client(transport=MockTransport(redirects))Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 290–291why, one step back290 url = "https://example.org/cross_domain"291 headers = {"Authorization": "abc"}Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 292why, one step back292 response = client.get(url, headers=headers)Replace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 293why, one step back293 assert response.url == "https://example.org/cross_domain_target"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 294–296why, one step back294 assert response.json()["headers"]["authorization"] == "abc"295296Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 297why, one step back297def test_body_redirect():Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 298–300why, one step back298 """299 A 308 redirect should preserve the request body.300 """Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 301why, one step back301 client = httpx.Client(transport=MockTransport(redirects))Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 302why, one step back302 url = "https://example.org/redirect_body"Seperate `content=...` and `data=...` parameters (#1266)Tom Christiebefore adoptionfeb404f
lines 303–304why, one step back303 content = b"Example request body"304 response = client.post(url, content=content)Replace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 305why, one step back305 assert response.url == "https://example.org/redirect_body_target"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 306–309why, one step back306 assert response.json()["body"] == "Example request body"307 assert "content-length" in response.json()["headers"]308309Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 310why, one step back310def test_no_body_redirect():Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 311–313why, one step back311 """312 A 303 redirect should remove the request body.313 """Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 314why, one step back314 client = httpx.Client(transport=MockTransport(redirects))Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 315why, one step back315 url = "https://example.org/redirect_no_body"Seperate `content=...` and `data=...` parameters (#1266)Tom Christiebefore adoptionfeb404f
lines 316–317why, one step back316 content = b"Example request body"317 response = client.post(url, content=content)Replace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 318why, one step back318 assert response.url == "https://example.org/redirect_body_target"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 319–322why, one step back319 assert response.json()["body"] == ""320 assert "content-length" not in response.json()["headers"]321322Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 323why, one step back323def test_can_stream_if_no_redirect():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 324why, one step back324 client = httpx.Client(transport=MockTransport(redirects))Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 325why, one step back325 url = "https://example.org/redirect_301"Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 326why, one step back326 with client.stream("GET", url, allow_redirects=False) as response:Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 327why, one step back327 assert not response.is_closedBetter test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 328why, one step back328 assert response.status_code == httpx.codes.MOVED_PERMANENTLYUse URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 329–331why, one step back329 assert response.headers["location"] == "https://example.org/"330331Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 332why, one step back332def test_cannot_redirect_streaming_body():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 333why, one step back333 client = httpx.Client(transport=MockTransport(redirects))Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 334–335why, one step back334 url = "https://example.org/redirect_body"335Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 336why, one step back336 def streaming_body():Increase test coverage - take 2 (#1012)Josep Cugatbefore adoption620b067
line 337why, one step back337 yield b"Example request body" # pragma: nocoverUse URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 338why, one step back338Drop ContentStream (#1295)Tom Christiebefore adoptionfbb21fb
line 339why, one step back339 with pytest.raises(httpx.StreamConsumed):Seperate `content=...` and `data=...` parameters (#1266)Tom Christiebefore adoptionfeb404f
line 340why, one step back340 client.post(url, content=streaming_body())Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 341–342why, one step back341342Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 343why, one step back343def test_cross_subdomain_redirect():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 344why, one step back344 client = httpx.Client(transport=MockTransport(redirects))Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 345why, one step back345 url = "https://example.com/cross_subdomain"Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 346why, one step back346 response = client.get(url)Replace httpx.URL for str in tests (#1237)Eduardo Enriquezbefore adoptionaad8209
line 347why, one step back347 assert response.url == "https://www.example.org/cross_subdomain"Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 348–349why, one step back348349Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 350–357why, one step back350def cookie_sessions(request: httpx.Request) -> httpx.Response:351 if request.url.path == "/":352 cookie = request.headers.get("Cookie")353 if cookie is not None:354 content = b"Logged in"355 else:356 content = b"Not logged in"357 return httpx.Response(200, content=content)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 358why, one step back358Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 359–368why, one step back359 elif request.url.path == "/login":360 status_code = httpx.codes.SEE_OTHER361 headers = {362 "location": "/",363 "set-cookie": (364 "session=eyJ1c2VybmFtZSI6ICJ0b21; path=/; Max-Age=1209600; "365 "httponly; samesite=lax"366 ),367 }368 return httpx.Response(status_code, headers=headers)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
line 369why, one step back369Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
lines 370–380why, one step back370 else:371 assert request.url.path == "/logout"372 status_code = httpx.codes.SEE_OTHER373 headers = {374 "location": "/",375 "set-cookie": (376 "session=null; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; "377 "httponly; samesite=lax"378 ),379 }380 return httpx.Response(status_code, headers=headers)Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 381–382why, one step back381382Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 383why, one step back383def test_redirect_cookie_behavior():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 384why, one step back384 client = httpx.Client(transport=MockTransport(cookie_sessions))Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 385–386why, one step back385386 # The client is not logged in.Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 387why, one step back387 response = client.get("https://example.com/")Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 388–391why, one step back388 assert response.url == "https://example.com/"389 assert response.text == "Not logged in"390391 # Login redirects to the homepage, setting a session cookie.Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 392why, one step back392 response = client.post("https://example.com/login")Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 393–396why, one step back393 assert response.url == "https://example.com/"394 assert response.text == "Logged in"395396 # The client is logged in.Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 397why, one step back397 response = client.get("https://example.com/")Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 398–401why, one step back398 assert response.url == "https://example.com/"399 assert response.text == "Logged in"400401 # Logout redirects to the homepage, expiring the session cookie.Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 402why, one step back402 response = client.post("https://example.com/logout")Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 403–406why, one step back403 assert response.url == "https://example.com/"404 assert response.text == "Not logged in"405406 # The client is not logged in.Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 407why, one step back407 response = client.get("https://example.com/")Use URLLib3 configuration options for URLLib3 transport (#970)Tom Christiebefore adoption225f1e2
lines 408–409why, one step back408 assert response.url == "https://example.com/"409 assert response.text == "Not logged in"Improve error when redirecting with custom schemes (#1002)Josep Cugatbefore adoption093cb42
lines 410–411why, one step back410411Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
line 412why, one step back412def test_redirect_custom_scheme():Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 413why, one step back413 client = httpx.Client(transport=MockTransport(redirects))Better test case consistency. Prefer `import httpx` and `httpx.Client`. (#1222)Tom Christiebefore adoption28c7205
lines 414–415why, one step back414 with pytest.raises(httpx.UnsupportedProtocol) as e:415 client.post("https://example.org/redirect_custom_scheme")Refactor tests to use `MockTransport(<handler_function>)` (#1281)Tom Christiebefore adoptionc2afd2d
line 416why, one step back416 assert str(e.value) == "Scheme 'market' not supported."