Revision bac6ea51 lib/http/client.py
b/lib/http/client.py | ||
---|---|---|
35 | 35 |
|
36 | 36 |
class HttpClientRequest(object): |
37 | 37 |
def __init__(self, host, port, method, path, headers=None, post_data=None, |
38 |
read_timeout=None, curl_config_fn=None, nicename=None): |
|
38 |
read_timeout=None, curl_config_fn=None, nicename=None, |
|
39 |
completion_cb=None): |
|
39 | 40 |
"""Describes an HTTP request. |
40 | 41 |
|
41 | 42 |
@type host: string |
... | ... | |
58 | 59 |
@type nicename: string |
59 | 60 |
@param nicename: Name, presentable to a user, to describe this request (no |
60 | 61 |
whitespace) |
62 |
@type completion_cb: callable accepting this request object as a single |
|
63 |
parameter |
|
64 |
@param completion_cb: Callback for request completion |
|
61 | 65 |
|
62 | 66 |
""" |
63 | 67 |
assert path.startswith("/"), "Path must start with slash (/)" |
64 | 68 |
assert curl_config_fn is None or callable(curl_config_fn) |
69 |
assert completion_cb is None or callable(completion_cb) |
|
65 | 70 |
|
66 | 71 |
# Request attributes |
67 | 72 |
self.host = host |
... | ... | |
71 | 76 |
self.read_timeout = read_timeout |
72 | 77 |
self.curl_config_fn = curl_config_fn |
73 | 78 |
self.nicename = nicename |
79 |
self.completion_cb = completion_cb |
|
74 | 80 |
|
75 | 81 |
if post_data is None: |
76 | 82 |
self.post_data = "" |
... | ... | |
220 | 226 |
req.resp_body = self._resp_buffer_read() |
221 | 227 |
|
222 | 228 |
# Ensure no potentially large variables are referenced |
223 |
try: |
|
224 |
# Only available in PycURL 7.19.0 and above |
|
225 |
reset_fn = curl.reset |
|
226 |
except AttributeError: |
|
227 |
curl.setopt(pycurl.POSTFIELDS, "") |
|
228 |
curl.setopt(pycurl.WRITEFUNCTION, lambda _: None) |
|
229 |
else: |
|
230 |
reset_fn() |
|
229 |
curl.setopt(pycurl.POSTFIELDS, "") |
|
230 |
curl.setopt(pycurl.WRITEFUNCTION, lambda _: None) |
|
231 |
|
|
232 |
if req.completion_cb: |
|
233 |
req.completion_cb(req) |
|
231 | 234 |
|
232 | 235 |
|
233 | 236 |
class _NoOpRequestMonitor: # pylint: disable=W0232 |
Also available in: Unified diff