]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Determine proxy based on path
authorSamuel Fekete <samuel.fekete@hogarthww.com>
Mon, 3 Jul 2017 12:13:02 +0000 (13:13 +0100)
committerSamuel Fekete <samuel.fekete@gmail.com>
Fri, 13 Jul 2018 15:40:35 +0000 (16:40 +0100)
vcr/stubs/__init__.py

index 52b57f48b639c6d8d66371f29867502f3d41d1c4..6ebe2e80d54f29c5372dd25c6c55abec2df172ff 100644 (file)
@@ -36,16 +36,6 @@ class VCRFakeSocket(object):
         """
         return 0  # wonder how bad this is....
 
-    def __nonzero__(self):
-        """This is hacky too.
-
-        urllib3 checks if sock is truthy before calling
-        set_tunnel (urllib3/connectionpool.py#L592).
-        If it is true, it never sets the tunnel and this
-        breaks proxy requests.
-        """
-        return False
-
 
 def parse_headers(header_list):
     """
@@ -140,15 +130,18 @@ class VCRConnection(object):
         """
         Returns empty string for the default port and ':port' otherwise
         """
-        port = self._tunnel_port or self.real_connection.port
+        port = self.real_connection.port
         default_port = {'https': 443, 'http': 80}[self._protocol]
         return ':{}'.format(port) if port != default_port else ''
 
     def _uri(self, url):
         """Returns request absolute URI"""
-        uri = "{}://{}{}{}".format(
+        if not url.startswith('/'):
+            # Then this must be a proxy request.
+            return url
+        uri = "{0}://{1}{2}{3}".format(
             self._protocol,
-            self._tunnel_host or self.real_connection.host,
+            self.real_connection.host,
             self._port_postfix(),
             url,
         )
@@ -158,7 +151,7 @@ class VCRConnection(object):
         """Returns request selector url from absolute URI"""
         prefix = "{}://{}{}".format(
             self._protocol,
-            self._tunnel_host or self.real_connection.host,
+            self.real_connection.host,
             self._port_postfix(),
         )
         return uri.replace(prefix, '', 1)
@@ -323,9 +316,6 @@ class VCRConnection(object):
         with force_reset():
             self.real_connection = self._baseclass(*args, **kwargs)
 
-        self._tunnel_host = None
-        self._tunnel_port = None
-
     def __setattr__(self, name, value):
         """
         We need to define this because any attributes that are set on the