forked from Yannik/qnap-letsencrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTTPServer.py
36 lines (30 loc) · 858 Bytes
/
HTTPServer.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
34
35
36
import socket, errno
from threading import Thread
try: # Python 2
from BaseHTTPServer import HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
except ImportError: # Python 3
from http.server import SimpleHTTPRequestHandler,HTTPServer
class HTTPServerV6(HTTPServer):
address_family = socket.AF_INET6
def main():
Thread(target=servev4).start()
try:
servev6()
except OSError as e:
if not e.errno == errno.EAFNOSUPPORT:
raise
def servev6():
try:
server = HTTPServerV6(('::', 80), SimpleHTTPRequestHandler)
server.serve_forever()
except socket.error as e:
if e.errno == errno.EAFNOSUPPORT: # system doesn't support ipv6
pass
else:
raise
def servev4():
server = HTTPServer(('0.0.0.0', 80), SimpleHTTPRequestHandler)
server.serve_forever()
if __name__ == '__main__':
main()