Skip to content
Myr

Properly encoded slashes when using `base_url` (#1407)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Florimond Manca · committed by GitHub · parent d0835da · Browse files · 2 files+13 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+13 added−3 removed

  • tests:+10 added−0 removed
  • other:+3 added−3 removed

2 files+13 added−3 removed

modified:httpx/_client.py+3 added-3 removed
118 unmodified lines
119 def trust_env(self) -> bool:120 return self._trust_env121122 def _enforce_trailing_slash(self, url: URL) -> URL:123 if url.path.endswith("/"):123 if url.raw_path.endswith(b"/"):124 return url125 return url.copy_with(path=url.path + "/")125 return url.copy_with(raw_path=url.raw_path + b"/")126127 def _get_proxy_map(128 self, proxies: typing.Optional[ProxiesTypes], allow_env_proxies: bool129 ) -> typing.Dict[str, typing.Optional[Proxy]]:
196 unmodified lines
326 merge_url = URL(url)327 if merge_url.is_relative_url:328 # We always ensure the base_url paths include the trailing '/',329 # and always strip any leading '/' from the merge URL.330 merge_url = merge_url.copy_with(path=merge_url.path.lstrip("/"))330 merge_url = merge_url.copy_with(raw_path=merge_url.raw_path.lstrip(b"/"))331 return self.base_url.join(merge_url)332 return merge_url333334 def _merge_cookies(
1522 unmodified lines
modified:tests/client/test_client.py+10 added
196 unmodified lines
197 request = client.build_request("GET", "../testing/123")198 assert request.url == "https://www.example.com/some/testing/123"199200201def test_merge_relative_url_with_encoded_slashes():202 client = httpx.Client(base_url="https://www.example.com/")203 request = client.build_request("GET", "/testing%2F123")204 assert request.url == "https://www.example.com/testing%2F123"205206 client = httpx.Client(base_url="https://www.example.com/base%2Fpath")207 request = client.build_request("GET", "/testing")208 assert request.url == "https://www.example.com/base%2Fpath/testing"209210211def test_pool_limits_deprecated():212 limits = httpx.Limits()213214 with pytest.warns(DeprecationWarning):
165 unmodified lines