]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Drop `Origin` from public API (#688)
authorAndrés Álvarez <BigChief45@users.noreply.github.com>
Tue, 7 Jan 2020 10:39:47 +0000 (04:39 -0600)
committerTom Christie <tom@tomchristie.com>
Tue, 7 Jan 2020 10:39:47 +0000 (10:39 +0000)
- 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 <tom@tomchristie.com>
httpx/__init__.py
httpx/client.py
httpx/dispatch/connection_pool.py
httpx/dispatch/proxy_http.py
httpx/models.py
tests/models/test_url.py

index ee5f8d0750931c9d76f3134f99c4971f9cbf6135..9c4f31b320e259a073063f94417047407cd8ae30 100644 (file)
@@ -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",
index c37c6b9c28e9f85fe4abdf0e8b5f5f75fb68933e..224baad776aff7b5cf578a9e6f73437fa5751e65 100644 (file)
@@ -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)
index 4ca2e5fd69370ce429f459406811e48bf72de9f9..eb2a11a5d053880338aab45cb59d12d78f5de3a4 100644 (file)
@@ -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)
index 915983601f24357921539119eec8da95248ffbbf..743e04d33f640fc7d5d6cdce4e8c8f376fbd732b 100644 (file)
@@ -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.
index 2994168dbdb72afc512e337db83ffb9161a30d0c..d0a438feafde71bd2ed9e2b67a54a790a2cbb86e 100644 (file)
@@ -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
index 491d0a4b46655b4d0b5bb1ecfc4d80108a4352fe..4be287d936e6091ef037f660e99e761493d479ea 100644 (file)
@@ -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(