diff --git a/demo/README.md b/demo/README.md index 041e53c..5054551 100644 --- a/demo/README.md +++ b/demo/README.md @@ -12,7 +12,7 @@ It consists of ## Setup instructions 1. Download the `demo/` directory. -2. Run `python server.py` in that directory. +2. Run `python server.py` in that directory (Use Python 3.5 or higher). 3. Navigate to `localhost:8000`. (**NOTE:** Clear-Site-Data only works on `localhost` and `https`. Since `server.py` is HTTP-only, navigating to other hosts than `localhost` will not work.) diff --git a/demo/server.py b/demo/server.py index 5adbad5..2d42bb1 100644 --- a/demo/server.py +++ b/demo/server.py @@ -1,7 +1,7 @@ -import BaseHTTPServer +import http.server import re -class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): +class RequestHandler(http.server.BaseHTTPRequestHandler): def do_GET(self): # Cache-Control: only-if-cached indicates that the browser should never # fetch the resource over network. Unfortunately, this is not widely @@ -21,14 +21,14 @@ def do_GET(self): return # Otherwise, just serve index.html, as that is the only page we have. - self.wfile.write(file('index.html').read()) + self.wfile.write(open('index.html', "r").read().encode()) def do_POST(self): # Serve index.html as usual, but with Clear-Site-Data as instructed # through the POST attributes. # Input: "types=cookies&types=cache" - post_data = self.rfile.read(int(self.headers['Content-Length'])) + post_data = self.rfile.read(int(self.headers['Content-Length'])).decode("utf-8") # Transformation: ['cookies', 'cache'] datatypes = re.findall('types=([^&]+)', post_data) # Output: '"cookies","cache"' @@ -39,9 +39,9 @@ def do_POST(self): self.send_header('Clear-Site-Data', datatypes) self.end_headers() - self.wfile.write(file('index.html').read()) + self.wfile.write(open('index.html', "r").read().encode()) if __name__ == "__main__": - httpd = BaseHTTPServer.HTTPServer(('', 8000), RequestHandler) + httpd = http.server.HTTPServer(('', 8000), RequestHandler) httpd.serve_forever()