Skip to content

Commit 54d70d8

Browse files
committed
Changed hostmap to be a named argument for compatibility
1 parent 00559f2 commit 54d70d8

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

browsermobproxy/client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,18 +281,18 @@ def timeouts(self, options):
281281
params)
282282
return r.status_code
283283

284-
def remap_hosts(self, hostmap):
284+
def remap_hosts(self, address=None, ip_address=None, hostmap={}):
285285
"""
286286
Remap the hosts for a specific URL
287287
288-
:param hostmap: A dictionary of url/ip_address pairs to remap
288+
:param address: url that you wish to remap
289+
:param ip_address: IP Address that will handle all traffic for the address passed in
290+
:param **hostmap: Other hosts to be added as keyword arguments
289291
"""
290-
if not isinstance(hostmap, dict):
291-
raise TypeError("hostmap needs to be a dictionary")
292-
293-
if not hostmap:
294-
raise Exception("hostmap should have at least one entry")
295-
292+
293+
if (address is not None and ip_address is not None):
294+
hostmap[address] = ip_address
295+
296296
r = requests.post('%s/proxy/%s/hosts' % (self.host, self.port),
297297
json.dumps(hostmap),
298298
headers={'content-type': 'application/json'})

test/test_client.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,14 @@ def test_remap_hosts(self):
225225
"""
226226
/proxy/:port/hosts
227227
"""
228-
status_code = self.client.remap_hosts({"example.com": "1.2.3.4"})
228+
status_code = self.client.remap_hosts("example.com", "1.2.3.4")
229+
assert(status_code == 200)
230+
231+
def test_remap_hosts_with_hostmap(self):
232+
"""
233+
/proxy/:port/hosts
234+
"""
235+
status_code = self.client.remap_hosts(hostmap={"example.com": "1.2.3.4"})
229236
assert(status_code == 200)
230237

231238
def test_wait_for_traffic_to_stop(self):

0 commit comments

Comments
 (0)