1
- from httplib2 import Http
1
+ #from httplib2 import Http
2
+ import requests
2
3
from urllib import urlencode
3
4
import json
4
5
@@ -11,9 +12,8 @@ def __init__(self, url):
11
12
- url: This is where the BrowserMob Proxy lives
12
13
"""
13
14
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 )
17
17
self .port = jcontent ['port' ]
18
18
url_parts = self .host .split (":" )
19
19
self .proxy = url_parts [0 ] + ":" + url_parts [1 ] + ":" + str (self .port )
@@ -24,31 +24,28 @@ def new_har(self, ref=None):
24
24
:Args:
25
25
- ref: A reference for the HAR. Defaults to None
26
26
"""
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 '' )
30
29
31
30
def new_page (self , ref ):
32
31
"""
33
32
This sets a new page to be recorded
34
33
:Args:
35
34
- ref: A reference for the new page. Defaults to None
36
35
"""
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 )
42
40
43
41
@property
44
42
def har (self ):
45
43
"""
46
44
Gets the HAR that has been recorded
47
45
"""
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 )
52
49
53
50
def selenium_proxy (self ):
54
51
"""
@@ -65,9 +62,8 @@ def whitelist(self, regexp, status_code):
65
62
- status_code: the HTTP status code to return for URLs that do not match the whitelist
66
63
67
64
"""
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
71
67
}))
72
68
73
69
@@ -79,10 +75,8 @@ def blacklist(self, regexp, status_code):
79
75
- status_code: the HTTP status code to return for URLs that do not match the blacklist
80
76
81
77
"""
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
86
80
}))
87
81
88
82
LIMITS = {
@@ -112,14 +106,11 @@ def limits(self, options):
112
106
if len (params .items ()) == 0 :
113
107
raise Exception ("You need to specify one of the valid Keys" )
114
108
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 ))
118
111
119
112
def close (self ):
120
113
"""
121
114
shuts down the proxy and closes the port
122
115
"""
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 ))
0 commit comments