gh-134168: fix http.server CLI support for IPv6 and --directory when serving over HTTPS (#134169)

This commit is contained in:
ggqlq 2025-05-24 20:19:20 +08:00 committed by GitHub
parent 5d9c8fe3f6
commit 2fd09b0110
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View file

@ -980,8 +980,8 @@ def test(HandlerClass=BaseHTTPRequestHandler,
HandlerClass.protocol_version = protocol
if tls_cert:
server = ThreadingHTTPSServer(addr, HandlerClass, certfile=tls_cert,
keyfile=tls_key, password=tls_password)
server = ServerClass(addr, HandlerClass, certfile=tls_cert,
keyfile=tls_key, password=tls_password)
else:
server = ServerClass(addr, HandlerClass)
@ -1041,7 +1041,7 @@ def _main(args=None):
parser.error(f"Failed to read TLS password file: {e}")
# ensure dual-stack is not disabled; ref #38907
class DualStackServer(ThreadingHTTPServer):
class DualStackServerMixin:
def server_bind(self):
# suppress exception when protocol is IPv4
@ -1054,9 +1054,16 @@ def _main(args=None):
self.RequestHandlerClass(request, client_address, self,
directory=args.directory)
class HTTPDualStackServer(DualStackServerMixin, ThreadingHTTPServer):
pass
class HTTPSDualStackServer(DualStackServerMixin, ThreadingHTTPSServer):
pass
ServerClass = HTTPSDualStackServer if args.tls_cert else HTTPDualStackServer
test(
HandlerClass=SimpleHTTPRequestHandler,
ServerClass=DualStackServer,
ServerClass=ServerClass,
port=args.port,
bind=args.bind,
protocol=args.protocol,

View file

@ -0,0 +1,2 @@
:mod:`http.server`: Fix IPv6 address binding and
:option:`--directory <http.server --directory>` handling when using HTTPS.