Skip to content

Instantly share code, notes, and snippets.

@libbkmz
Created November 7, 2012 11:18
Show Gist options
  • Select an option

  • Save libbkmz/4030921 to your computer and use it in GitHub Desktop.

Select an option

Save libbkmz/4030921 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from tornado import httpserver
from tornado import httpclient
from tornado import ioloop
from tornado import web
from tornado import options
class Application(web.RequestHandler):
@web.asynchronous
def get(self):
print "Get Request"
def body_chunk(response):
print "chunk readed %i" % len(response)
self.write(response)
self.flush()
def header_chunk(response):
print "header chunk readed"
def response_handler(response):
print "response accepted"
self.finish()
# import pdb; pdb.set_trace();
client = httpclient.AsyncHTTPClient()
client.configure("tornado.curl_httpclient.CurlAsyncHTTPClient")
req = httpclient.HTTPRequest(
url=self.request.uri,
method=self.request.method,
headers=self.request.headers,
streaming_callback=body_chunk,
# header_callback=header_chunk,
)
client.fetch(req, response_handler)
app = web.Application([
(r".*", Application),
])
options.parse_command_line()
app.listen(8888)
ioloop.IOLoop.instance().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment