]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
Updated Request with stup to support default ports
authorMax Shytikov <mshytikov@gmail.com>
Sun, 4 May 2014 00:06:21 +0000 (02:06 +0200)
committerMax Shytikov <mshytikov@gmail.com>
Sun, 4 May 2014 00:12:38 +0000 (02:12 +0200)
vcr/request.py
vcr/stubs/__init__.py

index 82517692dd5e298d424814d802c701fe9250a005..417c40c5b1fe00b72b0fcbbdd9858cf0d96be1f3 100644 (file)
@@ -28,7 +28,11 @@ class Request(object):
 
     @property
     def port(self):
-        return urlparse(self.uri).port
+        parse_uri = urlparse(self.uri)
+        port = parse_uri.port
+        if port is None:
+            port = {'https': 433, 'http': 80}[parse_uri.scheme]
+        return port
 
     @property
     def path(self):
index fc1491973fc7b1dee45bb1d19807159e87912aec..22187869d926dc3bfa4c9e81e454a5e596adb424 100644 (file)
@@ -119,21 +119,30 @@ class VCRConnection:
     # A reference to the cassette that's currently being patched in
     cassette = None
 
+    def _port_postfix(self):
+        """
+        Returns empty string for the default port and ':port' otherwise
+        """
+        port = self.real_connection.port
+        default_port = {'https': 433, 'http': 80}[self._protocol]
+        return ':{0}'.format(port) if port != default_port else ''
+
     def _uri(self, url):
         """Returns request absolute URI"""
-        return "{0}://{1}:{2}{3}".format(
+        uri = "{0}://{1}{2}{3}".format(
             self._protocol,
             self.real_connection.host,
-            self.real_connection.port,
+            self._port_postfix(),
             url,
         )
+        return uri
 
     def _url(self, uri):
         """Returns request selector url from absolute URI"""
-        prefix = "{0}://{1}:{2}".format(
+        prefix = "{0}://{1}{2}".format(
             self._protocol,
             self.real_connection.host,
-            self.real_connection.port,
+            self._port_postfix(),
         )
         return uri.replace(prefix, '', 1)