From: Andrés Álvarez Date: Tue, 7 Jan 2020 10:39:47 +0000 (-0600) Subject: Drop `Origin` from public API (#688) X-Git-Tag: 0.11.0~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b92a78c41544da0891d2c42c7e2a28174783c57;p=thirdparty%2Fhttpx.git Drop `Origin` from public API (#688) - Drop the url.origin property. - Drop Origin from the top-level export. - Use origin = Origin(url) in our internal usage, rather than url.origin. Closes #656 Co-authored-by: Tom Christie --- diff --git a/httpx/__init__.py b/httpx/__init__.py index ee5f8d07..9c4f31b3 100644 --- a/httpx/__init__.py +++ b/httpx/__init__.py @@ -26,7 +26,7 @@ from .exceptions import ( TooManyRedirects, WriteTimeout, ) -from .models import URL, Cookies, Headers, Origin, QueryParams, Request, Response +from .models import URL, Cookies, Headers, QueryParams, Request, Response from .status_codes import StatusCode, codes __all__ = [ @@ -76,7 +76,6 @@ __all__ = [ "StatusCode", "Cookies", "Headers", - "Origin", "QueryParams", "Request", "TimeoutException", diff --git a/httpx/client.py b/httpx/client.py index c37c6b9c..224baad7 100644 --- a/httpx/client.py +++ b/httpx/client.py @@ -39,6 +39,7 @@ from .models import ( CookieTypes, Headers, HeaderTypes, + Origin, QueryParams, QueryParamTypes, Request, @@ -511,7 +512,7 @@ class AsyncClient: """ headers = Headers(request.headers) - if url.origin != request.url.origin: + if Origin(url) != Origin(request.url): # Strip Authorization headers when responses are redirected away from # the origin. headers.pop("Authorization", None) diff --git a/httpx/dispatch/connection_pool.py b/httpx/dispatch/connection_pool.py index 4ca2e5fd..eb2a11a5 100644 --- a/httpx/dispatch/connection_pool.py +++ b/httpx/dispatch/connection_pool.py @@ -147,7 +147,7 @@ class ConnectionPool(AsyncDispatcher): async def send(self, request: Request, timeout: Timeout = None) -> Response: await self.check_keepalive_expiry() connection = await self.acquire_connection( - origin=request.url.origin, timeout=timeout + origin=Origin(request.url), timeout=timeout ) try: response = await connection.send(request, timeout=timeout) diff --git a/httpx/dispatch/proxy_http.py b/httpx/dispatch/proxy_http.py index 91598360..743e04d3 100644 --- a/httpx/dispatch/proxy_http.py +++ b/httpx/dispatch/proxy_http.py @@ -102,7 +102,7 @@ class HTTPProxy(ConnectionPool): logger.trace( f"forward_connection proxy_url={self.proxy_url!r} origin={origin!r}" ) - return await super().acquire_connection(self.proxy_url.origin, timeout) + return await super().acquire_connection(Origin(self.proxy_url), timeout) else: logger.trace( f"tunnel_connection proxy_url={self.proxy_url!r} origin={origin!r}" @@ -147,7 +147,7 @@ class HTTPProxy(ConnectionPool): await self.max_connections.acquire() connection = HTTPConnection( - self.proxy_url.origin, + Origin(self.proxy_url), ssl=self.tunnel_ssl, backend=self.backend, release_func=self.release_connection, @@ -188,7 +188,7 @@ class HTTPProxy(ConnectionPool): ) or self.proxy_mode == FORWARD_ONLY async def send(self, request: Request, timeout: Timeout = None) -> Response: - if self.should_forward_origin(request.url.origin): + if self.should_forward_origin(Origin(request.url)): # Change the request to have the target URL # as its full_path and switch the proxy URL # for where the request will be sent. diff --git a/httpx/models.py b/httpx/models.py index 2994168d..d0a438fe 100644 --- a/httpx/models.py +++ b/httpx/models.py @@ -192,10 +192,6 @@ class URL: def is_relative_url(self) -> bool: return not self.is_absolute_url - @property - def origin(self) -> "Origin": - return Origin(self) - def copy_with(self, **kwargs: typing.Any) -> "URL": if ( "username" in kwargs diff --git a/tests/models/test_url.py b/tests/models/test_url.py index 491d0a4b..4be287d9 100644 --- a/tests/models/test_url.py +++ b/tests/models/test_url.py @@ -1,6 +1,7 @@ import pytest -from httpx import URL, InvalidURL, Origin +from httpx import URL, InvalidURL +from httpx.models import Origin @pytest.mark.parametrize(