Listen on dual stack
This commit is contained in:
parent
4e8d4b93dd
commit
2de7107e55
1 changed files with 13 additions and 2 deletions
|
@ -1,11 +1,12 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from contextlib import suppress
|
||||
from http import HTTPStatus
|
||||
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
||||
from pathlib import Path
|
||||
from random import choices
|
||||
from signal import SIGTERM, signal
|
||||
from socket import socket
|
||||
from socket import AF_INET6, IPPROTO_IPV6, IPV6_V6ONLY, socket
|
||||
from sqlite3 import connect
|
||||
from string import ascii_lowercase
|
||||
from tempfile import gettempdir
|
||||
|
@ -111,7 +112,17 @@ class F2bRemoteRequestHandler(SimpleHTTPRequestHandler):
|
|||
do_HEAD = do_POST = __send_403
|
||||
|
||||
|
||||
server = ThreadingHTTPServer(
|
||||
class DualStackThreadingHttpServer(ThreadingHTTPServer):
|
||||
address_family = AF_INET6
|
||||
|
||||
def server_bind(self):
|
||||
# suppress exception when protocol is IPv4-only
|
||||
with suppress(OSError):
|
||||
self.socket.setsockopt(IPPROTO_IPV6, IPV6_V6ONLY, 0)
|
||||
return super().server_bind()
|
||||
|
||||
|
||||
server = DualStackThreadingHttpServer(
|
||||
server_address=('', 8000), RequestHandlerClass=F2bRemoteRequestHandler,
|
||||
bind_and_activate=True)
|
||||
|
||||
|
|
Loading…
Reference in a new issue