Last active
March 28, 2017 15:36
-
-
Save ayang/3199360 to your computer and use it in GitHub Desktop.
Dropbox proxy behind the GFW of China
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
#!/usr/bin/env python | |
import re | |
import tornado.ioloop | |
import tornado.web | |
from tornado import httpclient | |
class MainHandler(tornado.web.RequestHandler): | |
@tornado.web.asynchronous | |
def get(self): | |
print self.request.remote_ip, ":", self.request.full_url() | |
url = re.sub("notify(\d+).dropbox.com", "108.160.167.35", self.request.full_url()) | |
http_client = httpclient.AsyncHTTPClient() | |
http_client.fetch(url, self.handle_response, request_timeout=120.0) | |
def handle_response(self, response): | |
if response.error: | |
print "Can not connect." | |
self.write("{\"ret\": \"new\"}") | |
else: | |
print "Connect Successfull." | |
self.write(response.body) | |
self.finish() | |
application = tornado.web.Application([ | |
(r"/.*", MainHandler), | |
], debug=True) | |
if __name__ == "__main__": | |
application.listen(8889, xheaders=True) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment