From d38ecd7f767ba639d38a3c321e84013b8fa6e068 Mon Sep 17 00:00:00 2001 From: ccd0 Date: Sat, 1 Aug 2015 12:58:11 -0700 Subject: [PATCH] Allow reading script from local file. --- tools/proxy.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/proxy.py b/tools/proxy.py index 1e1bbbd19..cb80067bd 100755 --- a/tools/proxy.py +++ b/tools/proxy.py @@ -41,7 +41,10 @@ class RequestHandler(http.server.BaseHTTPRequestHandler): body = response.read() finally: conn.close() - body = body.replace(b'', b'', 1) + url = b'https://ccd0.github.io/4chan-x/builds/4chan-X.user.js' + if '/script.js' in resources: + url = b'http://localhost:8000/script.js' + body = body.replace(b'', b'', 1) self.send_response(response.status, response.reason) for header, value in response.getheaders(): if header.lower() not in ('date', 'connection', 'transfer-encoding', 'content-length'): @@ -55,6 +58,10 @@ class ThreadedHTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer): pass port = int(sys.argv[1]) if 1 < len(sys.argv) else 8000 +if 2 < len(sys.argv): + with open(sys.argv[2], 'rb') as f: + script = f.read() + resources['/script.js'] = ('application/javascript', script) server = ThreadedHTTPServer(('localhost', port), RequestHandler) thread = threading.Thread(target=server.serve_forever) thread.start()