Skip to content

Commit

Permalink
added httpProxy and httpsProxy functions. Added a keyword argument to…
Browse files Browse the repository at this point in the history
… the constructor, to allow remapping https requests towards the http proxy
  • Loading branch information
shyal committed Dec 13, 2016
1 parent e7f3198 commit d5c7da5
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions hoverpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def __init__(self,
destination="",
key="",
tlsVerification=True,
httpsToHttp=False
):
self._proxyPort = proxyPort
self._adminPort = adminPort
Expand All @@ -71,6 +72,7 @@ def __init__(self,
self._destination = destination
self._key = key
self._tlsVerification = tlsVerification
self._httpsToHttp = httpsToHttp
self.__enableProxy()
self.__start()

Expand Down Expand Up @@ -206,6 +208,15 @@ def addDelay(self, urlPattern="", delay=0, httpMethod=None):
delay["httpMethod"] = httpMethod
return self.delays(delays={"data": [delay]})

def httpProxy(self):
return "http://%s:%i" % (self._host, self._proxyPort)

def httpsProxy(self):
if self._httpsToHttp:
return self.httpProxy()
else:
return "https://%s:%i" % (self._host, self._proxyPort)

def __del__(self):
if self._process:
self.__stop()
Expand Down Expand Up @@ -239,11 +250,11 @@ def __enableProxy(self):
"""
Set the required environment variables to enable the use of hoverfly as a proxy.
"""
logging.debug("enabling proxy")
os.environ[
"HTTP_PROXY"] = "http://%s:%i" % (self._host, self._proxyPort)
"HTTP_PROXY"] = self.httpProxy()
os.environ[
"HTTPS_PROXY"] = "https://%s:%i" % (self._host, self._proxyPort)
"HTTPS_PROXY"] = self.httpsProxy()

os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(
os.path.dirname(
os.path.abspath(__file__)),
Expand Down

0 comments on commit d5c7da5

Please sign in to comment.