1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 17:15:35 +00:00

Updated Request with stup to support default ports

This commit is contained in:
Max Shytikov
2014-05-04 02:06:21 +02:00
parent 5d10a38160
commit 3322234b25
2 changed files with 18 additions and 5 deletions

View 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)