Skip to content

Commit 0e959d6

Browse files
just-be-devAutomatedTester
authored andcommitted
Change remap_hosts to accept dictionary
Signed-off-by: AutomatedTester <[email protected]>
2 parents 7def089 + 54d70d8 commit 0e959d6

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

browsermobproxy/client.py

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

284-
def remap_hosts(self, address, ip_address):
284+
def remap_hosts(self, address=None, ip_address=None, hostmap={}):
285285
"""
286286
Remap the hosts for a specific URL
287287
288-
289288
:param address: url that you wish to remap
290289
: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
291291
"""
292-
assert address is not None and ip_address is not None
292+
293+
if (address is not None and ip_address is not None):
294+
hostmap[address] = ip_address
295+
293296
r = requests.post('%s/proxy/%s/hosts' % (self.host, self.port),
294-
json.dumps({address: ip_address}),
297+
json.dumps(hostmap),
295298
headers={'content-type': 'application/json'})
296299
return r.status_code
297300

test/test_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ def test_remap_hosts(self):
228228
status_code = self.client.remap_hosts("example.com", "1.2.3.4")
229229
assert(status_code == 200)
230230

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"})
236+
assert(status_code == 200)
237+
231238
def test_wait_for_traffic_to_stop(self):
232239
"""
233240
/proxy/:port/wait

0 commit comments

Comments
 (0)