mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 09:13:23 +00:00
Fix host and port for proxy connections
This commit is contained in:
committed by
Samuel Fekete
parent
aff71c5107
commit
43f4eb8156
@@ -18,7 +18,7 @@ log = logging.getLogger(__name__)
|
|||||||
class VCRFakeSocket(object):
|
class VCRFakeSocket(object):
|
||||||
"""
|
"""
|
||||||
A socket that doesn't do anything!
|
A socket that doesn't do anything!
|
||||||
Used when playing back casssettes, when there
|
Used when playing back cassettes, when there
|
||||||
is no actual open socket.
|
is no actual open socket.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -36,6 +36,16 @@ class VCRFakeSocket(object):
|
|||||||
"""
|
"""
|
||||||
return 0 # wonder how bad this is....
|
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):
|
def parse_headers(header_list):
|
||||||
"""
|
"""
|
||||||
@@ -130,7 +140,7 @@ class VCRConnection(object):
|
|||||||
"""
|
"""
|
||||||
Returns empty string for the default port and ':port' otherwise
|
Returns empty string for the default port and ':port' otherwise
|
||||||
"""
|
"""
|
||||||
port = self.real_connection.port
|
port = self._tunnel_port or self.real_connection.port
|
||||||
default_port = {'https': 443, 'http': 80}[self._protocol]
|
default_port = {'https': 443, 'http': 80}[self._protocol]
|
||||||
return ':{}'.format(port) if port != default_port else ''
|
return ':{}'.format(port) if port != default_port else ''
|
||||||
|
|
||||||
@@ -138,7 +148,7 @@ class VCRConnection(object):
|
|||||||
"""Returns request absolute URI"""
|
"""Returns request absolute URI"""
|
||||||
uri = "{}://{}{}{}".format(
|
uri = "{}://{}{}{}".format(
|
||||||
self._protocol,
|
self._protocol,
|
||||||
self.real_connection.host,
|
self._tunnel_host or self.real_connection.host,
|
||||||
self._port_postfix(),
|
self._port_postfix(),
|
||||||
url,
|
url,
|
||||||
)
|
)
|
||||||
@@ -148,7 +158,7 @@ class VCRConnection(object):
|
|||||||
"""Returns request selector url from absolute URI"""
|
"""Returns request selector url from absolute URI"""
|
||||||
prefix = "{}://{}{}".format(
|
prefix = "{}://{}{}".format(
|
||||||
self._protocol,
|
self._protocol,
|
||||||
self.real_connection.host,
|
self._tunnel_host or self.real_connection.host,
|
||||||
self._port_postfix(),
|
self._port_postfix(),
|
||||||
)
|
)
|
||||||
return uri.replace(prefix, '', 1)
|
return uri.replace(prefix, '', 1)
|
||||||
@@ -313,6 +323,9 @@ class VCRConnection(object):
|
|||||||
with force_reset():
|
with force_reset():
|
||||||
self.real_connection = self._baseclass(*args, **kwargs)
|
self.real_connection = self._baseclass(*args, **kwargs)
|
||||||
|
|
||||||
|
self._tunnel_host = None
|
||||||
|
self._tunnel_port = None
|
||||||
|
|
||||||
def __setattr__(self, name, value):
|
def __setattr__(self, name, value):
|
||||||
"""
|
"""
|
||||||
We need to define this because any attributes that are set on the
|
We need to define this because any attributes that are set on the
|
||||||
|
|||||||
Reference in New Issue
Block a user