From 8944cc072eee2f960a2e1ec59dafc715e979ccb6 Mon Sep 17 00:00:00 2001 From: codeskyblue Date: Mon, 1 Aug 2016 10:24:06 +0800 Subject: [PATCH] add plist proxy --- scripts/proxy.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/scripts/proxy.py b/scripts/proxy.py index 46df825..64fea18 100644 --- a/scripts/proxy.py +++ b/scripts/proxy.py @@ -2,6 +2,7 @@ # coding: utf-8 import time +import hashlib import tornado import tornado.ioloop @@ -39,11 +40,34 @@ class ProxyHandler(tornado.web.RequestHandler): self.write(response.body) self.finish() +class PlistStoreHandler(tornado.web.RequestHandler): + db = {} + + def post(self): + body = self.request.body + if len(body) > 5000: + self.set_status(500) + self.finish("request body too long") + m = hashlib.md5() + m.update(body) + key = m.hexdigest()[8:16] + self.db[key] = body + self.write({'key': key}) + + def get(self): + key = self.get_argument('key') + value = self.db.get(key) + if value is None: + raise tornado.web.HTTPError(404) + self.set_header('Content-Type', 'text/xml') + self.finish(value) + def make_app(debug=True): return tornado.web.Application([ (r"/", MainHandler), (r"/proxy/(.*)", ProxyHandler), + (r"/plist", PlistStoreHandler), ], debug=debug) @@ -51,4 +75,4 @@ if __name__ == "__main__": app = make_app() tornado.options.parse_command_line() app.listen(options.port) - ioloop.IOLoop.current().start() \ No newline at end of file + ioloop.IOLoop.current().start()