Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add streaming_callback option to httpclient

  • Loading branch information...
commit 6e1cb0ddf45c968e74db570c6c0499cb0ff321e4 1 parent 237944d
paul authored
Showing with 6 additions and 2 deletions.
  1. +6 −2 tornado/httpclient.py
View
8 tornado/httpclient.py
@@ -256,7 +256,7 @@ def __init__(self, url, method="GET", headers={}, body=None,
connect_timeout=None, request_timeout=None,
if_modified_since=None, follow_redirects=True,
max_redirects=5, user_agent=None, use_gzip=True,
- network_interface=None):
+ network_interface=None, streaming_callback=None):
if if_modified_since:
timestamp = calendar.timegm(if_modified_since.utctimetuple())
headers["If-Modified-Since"] = email.utils.formatdate(
@@ -276,6 +276,7 @@ def __init__(self, url, method="GET", headers={}, body=None,
self.user_agent = user_agent
self.use_gzip = use_gzip
self.network_interface = network_interface
+ self.streaming_callback = streaming_callback
class HTTPResponse(object):
@@ -339,7 +340,10 @@ def _curl_setup_request(curl, request, buffer, headers):
except:
# Old version of curl; response will not include headers
pass
- curl.setopt(pycurl.WRITEFUNCTION, buffer.write)
+ if request.streaming_callback:
+ curl.setopt(pycurl.WRITEFUNCTION, request.streaming_callback)
+ else:
+ curl.setopt(pycurl.WRITEFUNCTION, buffer.write)
curl.setopt(pycurl.FOLLOWLOCATION, request.follow_redirects)
curl.setopt(pycurl.MAXREDIRS, request.max_redirects)
curl.setopt(pycurl.CONNECTTIMEOUT, int(request.connect_timeout))
Please sign in to comment.
Something went wrong with that request. Please try again.