mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Updated Request with stup to support default ports
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user