Skip to content

Commit f67e58d

Browse files
committed
urlrequest: add method paramaters, and correctly set to GET or POST by default (according to the documentation.)
1 parent 21b6016 commit f67e58d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

kivy/network/urlrequest.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ def bug_posted(req, result):
7272
class UrlRequest(Thread):
7373
'''Url request. See module documentation for usage.
7474
75+
.. versionchanged::
76+
Add `method` parameters
77+
7578
:Parameters:
7679
`url`: str
7780
Complete url string to call.
@@ -97,10 +100,13 @@ class UrlRequest(Thread):
97100
on_progress.
98101
`timeout`: int, default to None
99102
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
100105
'''
101106

102107
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):
104110
super(UrlRequest, self).__init__()
105111
self._queue = deque()
106112
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,
116122
self._resp_length = -1
117123
self._chunk_size = chunk_size
118124
self._timeout = timeout
125+
self._method = method
119126

120127
#: Url of the request
121128
self.url = url
@@ -182,7 +189,10 @@ def _fetch_url(http://github.com/self,%20url,%20body,%20headers,%20q):
182189
path += '#' + parse.fragment
183190

184191
# 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 {})
186196

187197
# read header
188198
resp = req.getresponse()

0 commit comments

Comments
 (0)