Serve a fresh copy of the file.
This commit is contained in:
parent
d38ecd7f76
commit
88a0f4db60
@ -1,14 +1,24 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import http.server, http.client, socketserver, threading, sys, re
|
import http.server, http.client, socketserver, threading, sys, re
|
||||||
|
|
||||||
proxyConfig = b'''function FindProxyForURL(url, host) {
|
def proxyConfig():
|
||||||
if (/^http:\/\/boards\.4chan\.org\//.test(url)) {
|
data = b'''function FindProxyForURL(url, host) {
|
||||||
return 'PROXY localhost:8000';
|
if (/^http:\/\/boards\.4chan\.org\//.test(url)) {
|
||||||
|
return 'PROXY localhost:8000';
|
||||||
|
}
|
||||||
|
return 'DIRECT';
|
||||||
}
|
}
|
||||||
return 'DIRECT';
|
'''
|
||||||
}
|
return 'application/x-javascript-config', data
|
||||||
'''
|
|
||||||
resources = {'/proxy.pac': ('application/x-javascript-config', proxyConfig)}
|
def localScript(filename):
|
||||||
|
def handler():
|
||||||
|
with open(filename, 'rb') as f:
|
||||||
|
data = f.read()
|
||||||
|
return 'application/javascript', data
|
||||||
|
return handler
|
||||||
|
|
||||||
|
resources = {'/proxy.pac': proxyConfig}
|
||||||
|
|
||||||
class RequestHandler(http.server.BaseHTTPRequestHandler):
|
class RequestHandler(http.server.BaseHTTPRequestHandler):
|
||||||
def do_HEAD(self):
|
def do_HEAD(self):
|
||||||
@ -22,7 +32,7 @@ class RequestHandler(http.server.BaseHTTPRequestHandler):
|
|||||||
|
|
||||||
def local(self):
|
def local(self):
|
||||||
if self.path in resources:
|
if self.path in resources:
|
||||||
mimeType, data = resources[self.path]
|
mimeType, data = resources[self.path]()
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
self.send_header('Content-Type', mimeType)
|
self.send_header('Content-Type', mimeType)
|
||||||
self.send_header('Content-Length', len(data))
|
self.send_header('Content-Length', len(data))
|
||||||
@ -59,9 +69,7 @@ class ThreadedHTTPServer(socketserver.ThreadingMixIn, http.server.HTTPServer):
|
|||||||
|
|
||||||
port = int(sys.argv[1]) if 1 < len(sys.argv) else 8000
|
port = int(sys.argv[1]) if 1 < len(sys.argv) else 8000
|
||||||
if 2 < len(sys.argv):
|
if 2 < len(sys.argv):
|
||||||
with open(sys.argv[2], 'rb') as f:
|
resources['/script.js'] = localScript(sys.argv[2])
|
||||||
script = f.read()
|
|
||||||
resources['/script.js'] = ('application/javascript', script)
|
|
||||||
server = ThreadedHTTPServer(('localhost', port), RequestHandler)
|
server = ThreadedHTTPServer(('localhost', port), RequestHandler)
|
||||||
thread = threading.Thread(target=server.serve_forever)
|
thread = threading.Thread(target=server.serve_forever)
|
||||||
thread.start()
|
thread.start()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user