Created
March 26, 2020 10:54
-
-
Save m-242/1226349cf7395b0d21a5148a97d0b0c7 to your computer and use it in GitHub Desktop.
A stupid redirection looping server, because why rewrite it each time I use it ?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from http.server import HTTPServer, BaseHTTPRequestHandler | |
class redirectHandler(BaseHTTPRequestHandler): | |
def do_GET(self): | |
""" Looping redirections """ | |
path = "/a" if self.path == "/b" else "/b" | |
self.send_response(301) | |
self.send_header("Location", path) | |
self.end_headers() | |
PORT = 80 | |
print(f"serving at port {PORT}") | |
HTTPServer(("", PORT), redirectHandler).serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With the help of this answer.