Skip to content

Instantly share code, notes, and snippets.

@cloverstd
Created September 27, 2016 12:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cloverstd/3da5d17d768eece95782ad73549f5521 to your computer and use it in GitHub Desktop.
Save cloverstd/3da5d17d768eece95782ad73549f5521 to your computer and use it in GitHub Desktop.
Tornado forward HTTP Form upload
import tornado.gen
import tornado.web
import tornado.ioloop
import tornado.httpclient
import tornado.tcpclient
class ProxyHandler(tornado.web.RequestHandler):
@tornado.gen.coroutine
def post(self):
url = "http://127.0.0.1:8080/v1/registry/api/registry/293809f6a2f84c299904b12a75f60d2c/images/5b90564c68024665bd36ddc06f54a71f/cover?token=e3c189c6d3984a439ebe9d6c54fb644d"
http_client = tornado.httpclient.AsyncHTTPClient()
content_type = self.request.headers.get('Content-Type')
content_length = self.request.headers.get('Content-Length')
res = yield http_client.fetch(
url,
method='PUT',
headers={
"Content-Type": content_type,
"Content-Length": content_length
},
body=self.request.body
)
self.write(res.body)
if __name__ == '__main__':
app = tornado.web.Application(
[(r'/', ProxyHandler)],
debug=True
)
app.listen(9990)
tornado.ioloop.IOLoop.current().start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment