Skip to content

Commit 91d1e56

Browse files
author
AutomatedTester
committed
add
1 parent c705792 commit 91d1e56

File tree

2 files changed

+22
-31
lines changed

2 files changed

+22
-31
lines changed

browsermobproxy/client.py

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from httplib2 import Http
1+
#from httplib2 import Http
2+
import requests
23
from urllib import urlencode
34
import json
45

@@ -11,9 +12,8 @@ def __init__(self, url):
1112
- url: This is where the BrowserMob Proxy lives
1213
"""
1314
self.host = url
14-
h = Http()
15-
resp, content = h.request('%s/proxy' % self.host, 'POST', urlencode(''))
16-
jcontent = json.loads(content)
15+
resp = requests.post('%s/proxy' % self.host, urlencode(''))
16+
jcontent = json.loads(resp.content)
1717
self.port = jcontent['port']
1818
url_parts = self.host.split(":")
1919
self.proxy = url_parts[0] + ":" + url_parts[1] + ":" + str(self.port)
@@ -24,31 +24,28 @@ def new_har(self, ref=None):
2424
:Args:
2525
- ref: A reference for the HAR. Defaults to None
2626
"""
27-
h = Http()
28-
resp, content = h.request('%s/proxy/%s/har' % (self.host, self.port),
29-
'PUT', ref or '')
27+
requests.put('%s/proxy/%s/har' % (self.host, self.port),
28+
ref or '')
3029

3130
def new_page(self, ref):
3231
"""
3332
This sets a new page to be recorded
3433
:Args:
3534
- ref: A reference for the new page. Defaults to None
3635
"""
37-
h = Http()
38-
resp, content = h.request('%s/proxy/%s/har/pageRef' % (self.host, self.port),
39-
'PUT', ref or '')
40-
if content:
41-
return json.loads(content)
36+
resp = requests.put('%s/proxy/%s/har/pageRef' % (self.host, self.port),
37+
ref or '')
38+
if resp.content:
39+
return json.loads(resp.content)
4240

4341
@property
4442
def har(self):
4543
"""
4644
Gets the HAR that has been recorded
4745
"""
48-
h = Http()
49-
resp, content = h.request('%s/proxy/%s/har' % (self.host, self.port),
50-
'GET')
51-
return json.loads(content)
46+
resp = requests.get('%s/proxy/%s/har' % (self.host, self.port))
47+
48+
return json.loads(resp.content)
5249

5350
def selenium_proxy(self):
5451
"""
@@ -65,9 +62,8 @@ def whitelist(self, regexp, status_code):
6562
- status_code: the HTTP status code to return for URLs that do not match the whitelist
6663
6764
"""
68-
h = Http()
69-
resp, content = h.request('%s/proxy/%s/whitelist' % (self.host, self.port),
70-
'PUT', urlencode({ 'regex': regexp, 'status': status_code
65+
resp = requests.put('%s/proxy/%s/whitelist' % (self.host, self.port),
66+
urlencode({ 'regex': regexp, 'status': status_code
7167
}))
7268

7369

@@ -79,10 +75,8 @@ def blacklist(self, regexp, status_code):
7975
- status_code: the HTTP status code to return for URLs that do not match the blacklist
8076
8177
"""
82-
83-
h = Http()
84-
resp, content = h.request('%s/proxy/%s/blacklist' % (self.host, self.port),
85-
'PUT', urlencode({ 'regex': regexp, 'status': status_code
78+
resp = requests.put('%s/proxy/%s/blacklist' % (self.host, self.port),
79+
urlencode({ 'regex': regexp, 'status': status_code
8680
}))
8781

8882
LIMITS = {
@@ -112,14 +106,11 @@ def limits(self, options):
112106
if len(params.items()) == 0:
113107
raise Exception("You need to specify one of the valid Keys")
114108

115-
h = Http()
116-
resp, content = h.request('%s/proxy/%s/limit' % (self.host, self.port),
117-
'PUT', urlencode(params))
109+
resp = requests.put('%s/proxy/%s/limit' % (self.host, self.port),
110+
urlencode(params))
118111

119112
def close(self):
120113
"""
121114
shuts down the proxy and closes the port
122115
"""
123-
h = Http()
124-
resp, content = h.request('%s/proxy/%s' % (self.host, self.port),
125-
'DELETE' )
116+
resp = requests.delete('%s/proxy/%s' % (self.host, self.port))

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup, find_packages
22

33
setup(name='browsermob-proxy',
4-
version='0.0.1',
4+
version='0.1.0',
55
description='A library for interacting with the Browsermob Proxy',
66
author='David Burns',
77
author_email='david.burns at theautomatedtester dot co dot uk',
@@ -16,5 +16,5 @@
1616
'Topic :: Software Development :: Libraries',
1717
'Programming Language :: Python'],
1818
packages = find_packages(),
19-
install_requires=['httplib2==0.7.0'],
19+
install_requires=['requests==0.10.7'],
2020
)

0 commit comments

Comments
 (0)