Skip to content

Instantly share code, notes, and snippets.

@ayang
Last active March 28, 2017 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ayang/3199360 to your computer and use it in GitHub Desktop.
Save ayang/3199360 to your computer and use it in GitHub Desktop.
Dropbox proxy behind the GFW of China
#!/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