]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
add streaming_callback option to httpclient
authorpaul <paul@viper1.(none)>
Thu, 17 Sep 2009 05:59:42 +0000 (22:59 -0700)
committerpaul <paul@viper1.(none)>
Thu, 17 Sep 2009 05:59:42 +0000 (22:59 -0700)
tornado/httpclient.py

index cd37b106f2ac6d8585894332bd9c4642b3c7a89b..102dda2a89b9a76127b5c74c3fab736d99a50e54 100644 (file)
@@ -256,7 +256,7 @@ class HTTPRequest(object):
                  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 @@ class HTTPRequest(object):
         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))