@@ -72,6 +72,9 @@ def bug_posted(req, result):
72
72
class UrlRequest (Thread ):
73
73
'''Url request. See module documentation for usage.
74
74
75
+ .. versionchanged::
76
+ Add `method` parameters
77
+
75
78
:Parameters:
76
79
`url`: str
77
80
Complete url string to call.
@@ -97,10 +100,13 @@ class UrlRequest(Thread):
97
100
on_progress.
98
101
`timeout`: int, default to None
99
102
If set, blocking operations will timeout after that many seconds.
103
+ `method'`: str, default to 'GET' (or 'POST' if body)
104
+ HTTP method to use
100
105
'''
101
106
102
107
def __init__ (self , url , on_success = None , on_error = None , on_progress = None ,
103
- req_body = None , req_headers = None , chunk_size = 8192 , timeout = None ):
108
+ req_body = None , req_headers = None , chunk_size = 8192 , timeout = None ,
109
+ method = None ):
104
110
super (UrlRequest , self ).__init__ ()
105
111
self ._queue = deque ()
106
112
self ._trigger_result = Clock .create_trigger (self ._dispatch_result , 0 )
@@ -116,6 +122,7 @@ def __init__(self, url, on_success=None, on_error=None, on_progress=None,
116
122
self ._resp_length = - 1
117
123
self ._chunk_size = chunk_size
118
124
self ._timeout = timeout
125
+ self ._method = method
119
126
120
127
#: Url of the request
121
128
self .url = url
@@ -182,7 +189,10 @@ def _fetch_url(http://github.com/self,%20url,%20body,%20headers,%20q):
182
189
path += '#' + parse .fragment
183
190
184
191
# send request
185
- req .request ('GET' , path , body , headers or {})
192
+ method = self ._method
193
+ if method is None :
194
+ method = 'GET' if body is None else 'POST'
195
+ req .request (method , path , body , headers or {})
186
196
187
197
# read header
188
198
resp = req .getresponse ()
0 commit comments