]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Clean up '_dispatcher_for_request' into 'dispatcher_for_url' (#561)
authorTom Christie <tom@tomchristie.com>
Fri, 29 Nov 2019 11:21:40 +0000 (11:21 +0000)
committerGitHub <noreply@github.com>
Fri, 29 Nov 2019 11:21:40 +0000 (11:21 +0000)
httpx/client.py
tests/client/test_proxies.py

index 30e2181e4dd41aa4268961c0177c2d4a4d3d12e3..4c594f2b09cc2f81f1e14e56f6922324e62c6f7c 100644 (file)
@@ -535,7 +535,7 @@ class Client:
         Sends a single request, without handling any redirections.
         """
 
-        dispatcher = self._dispatcher_for_request(request, self.proxies)
+        dispatcher = self.dispatcher_for_url(request.url)
 
         try:
             with ElapsedTimer() as timer:
@@ -560,12 +560,12 @@ class Client:
 
         return response
 
-    def _dispatcher_for_request(
-        self, request: Request, proxies: typing.Dict[str, Dispatcher]
-    ) -> Dispatcher:
-        """Gets the Dispatcher instance that should be used for a given Request"""
-        if proxies:
-            url = request.url
+    def dispatcher_for_url(self, url: URL) -> Dispatcher:
+        """
+        Returns the Dispatcher instance that should be used for a given URL.
+        This will either be the standard connection pool, or a proxy.
+        """
+        if self.proxies:
             is_default_port = (url.scheme == "http" and url.port == 80) or (
                 url.scheme == "https" and url.port == 443
             )
@@ -579,8 +579,8 @@ class Client:
                 "all",
             )
             for proxy_key in proxy_keys:
-                if proxy_key and proxy_key in proxies:
-                    dispatcher = proxies[proxy_key]
+                if proxy_key and proxy_key in self.proxies:
+                    dispatcher = self.proxies[proxy_key]
                     return dispatcher
 
         return self.dispatch
index 1c02ce8c4b4d4ed5577eaa72e080a145caa16de2..fc1e57a5e851e887dbef4604bc8584242be8bb21 100644 (file)
@@ -102,8 +102,7 @@ PROXY_URL = "http://[::1]"
 )
 def test_dispatcher_for_request(url, proxies, expected):
     client = httpx.Client(proxies=proxies)
-    request = httpx.Request("GET", url)
-    dispatcher = client._dispatcher_for_request(request, client.proxies)
+    dispatcher = client.dispatcher_for_url(httpx.URL(url))
 
     if expected is None:
         assert isinstance(dispatcher, httpx.ConnectionPool)