Skip to content
Myr

Drop private Origin model (#1070)

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

* Drop private Origin model * Drop Origin from docs * Update tests/test_utils.py Co-authored-by: Florimond Manca <florimond.manca@gmail.com> * Drop full_path test

authored by Tom Christie · committed by GitHub · parent 20f4911 · Browse files · 6 files+27 added−73 removed
This commit

State

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

Trailers

  • Co-authored-by: Florimond Manca <florimond.manca@gmail.com>

Diff stats

6 files+27 added−73 removed

  • tests:+13 added−22 removed
  • other:+14 added−51 removed

6 files+27 added−73 removed

modified:docs/api.md-17 removed
modified:httpx/_client.py+3 added-2 removed
24 unmodified lines
25 RequestBodyUnavailable,26 TooManyRedirects,27 map_exceptions,28)29from ._models import URL, Cookies, Headers, Origin, QueryParams, Request, Response29from ._models import URL, Cookies, Headers, QueryParams, Request, Response30from ._status_codes import codes31from ._transports.asgi import ASGITransport32from ._transports.wsgi import WSGITransport33from ._types import (
12 unmodified lines
46from ._utils import (47 NetRCInfo,48 get_environment_proxies,49 get_logger,50 same_origin,51 should_not_be_proxied,52)5354logger = get_logger(__name__)
291 unmodified lines
346 Return the headers that should be used for the redirect request.347 """348 headers = Headers(request.headers)349349 if Origin(url) != Origin(request.url):350 if not same_origin(url, request.url):351 # Strip Authorization headers when responses are redirected away from352 # the origin.353 headers.pop("Authorization", None)354 headers["Host"] = url.authority
1166 unmodified lines
modified:httpx/_models.py-31 removed
232 unmodified lines
233 )234 return f"{class_name}({url_str!r})"235236237class Origin:238 """239 The URL scheme and authority information, as a comparable, hashable object.240 """241242 def __init__(self, url: URLTypes) -> None:243 if not isinstance(url, URL):244 url = URL(url)245 self.scheme = url.scheme246 self.is_ssl = url.is_ssl247 self.host = url.host248 self.port = url.port249250 def __eq__(self, other: typing.Any) -> bool:251 return (252 isinstance(other, self.__class__)253 and self.scheme == other.scheme254 and self.host == other.host255 and self.port == other.port256 )257258 def __hash__(self) -> int:259 return hash((self.scheme, self.host, self.port))260261 def __repr__(self) -> str:262 class_name = self.__class__.__name__263 return (264 f"{class_name}(scheme={self.scheme!r} host={self.host!r} port={self.port})"265 )266267237class QueryParams(typing.Mapping[str, str]):238 """239 URL query parameters, as a multi-dict.240 """
913 unmodified lines
modified:httpx/_utils.py+11 added-1 removed
258 unmodified lines
259260 return typing.cast(Logger, logger)261262263def same_origin(url: "URL", other: "URL") -> bool:264 """265 Return 'True' if the given URLs share the same origin.266 """267 return (268 url.scheme == other.scheme and url.host == other.host and url.port == other.port269 )270271272def should_not_be_proxied(url: "URL") -> bool:273 """264 """ Return True if url should not be proxied,274 Return True if url should not be proxied,275 return False otherwise.276 """277 no_proxy = getproxies().get("no")278 if not no_proxy:
130 unmodified lines
modified:tests/models/test_url.py-22 removed
1import pytest23from httpx import URL, InvalidURL4from httpx._models import Origin456@pytest.mark.parametrize(7 "given,idna,host,scheme,port",
167 unmodified lines
175176 assert all(url in urls for url in url_set)177178180def test_origin_from_url_string():181 origin = Origin("https://example.com")182 assert origin.scheme == "https"183 assert origin.is_ssl184 assert origin.host == "example.com"185 assert origin.port == 443186187188def test_origin_repr():189 origin = Origin("https://example.com:8080")190 assert str(origin) == "Origin(scheme='https' host='example.com' port=8080)"191192193def test_origin_equal():194 origin1 = Origin("https://example.com")195 origin2 = Origin("https://example.com")196 assert origin1 is not origin2197 assert origin1 == origin2198 assert len({origin1, origin2}) == 1199200179def test_url_copywith_for_authority():180 copy_with_kwargs = {181 "username": "username",182 "password": "password",
8 unmodified lines
modified:tests/test_utils.py+13 added
10 unmodified lines
11 get_environment_proxies,12 guess_json_utf,13 obfuscate_sensitive_headers,14 parse_header_links,15 same_origin,16 should_not_be_proxied,17)18from tests.utils import override_log_level19
274 unmodified lines
294def test_should_not_be_proxied(url, no_proxy, expected):295 os.environ.update(no_proxy)296 parsed_url = httpx.URL(url)297 assert should_not_be_proxied(parsed_url) == expected298299300def test_same_origin():301 origin1 = httpx.URL("https://example.com")302 origin2 = httpx.URL("HTTPS://EXAMPLE.COM:443")303 assert same_origin(origin1, origin2)304305306def test_not_same_origin():307 origin1 = httpx.URL("https://example.com")308 origin2 = httpx.URL("HTTP://EXAMPLE.COM")309 assert not same_origin(origin1, origin2)