-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
33 lines (23 loc) · 782 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import SimpleHTTPServer
import SocketServer
def redirect_handler_factory():
"""
Returns a request handler class that redirects to supplied `url`
"""
class RedirectHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(301)
domain = self.headers['host']
if ':' in domain:
domain = domain.split(':')[0]
self.send_header('Location', "https://" + domain + self.path)
self.end_headers()
return RedirectHandler
def main():
port = 80
host = '0.0.0.0'
redirectHandler = redirect_handler_factory()
handler = SocketServer.TCPServer((host, port), redirectHandler)
handler.serve_forever()
if __name__ == "__main__":
main()