Created
September 27, 2016 12:48
-
-
Save cloverstd/3da5d17d768eece95782ad73549f5521 to your computer and use it in GitHub Desktop.
Tornado forward HTTP Form upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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