https://github.com/python/cpython/commit/2fd09b011031f3c00c342b44e02e2817010e507c
commit: 2fd09b011031f3c00c342b44e02e2817010e507c
branch: main
author: ggqlq <124190229+gg...@users.noreply.github.com>
committer: picnixz <10796600+picn...@users.noreply.github.com>
date: 2025-05-24T12:19:20Z
summary:

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

files:
A Misc/NEWS.d/next/Library/2025-05-18-13-23-29.gh-issue-134168.hgx3Xg.rst
M Lib/http/server.py

diff --git a/Lib/http/server.py b/Lib/http/server.py
index f6d1b998f4201e..ef10d185932633 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -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 finish_request(self, request, client_address):
             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,
diff --git 
a/Misc/NEWS.d/next/Library/2025-05-18-13-23-29.gh-issue-134168.hgx3Xg.rst 
b/Misc/NEWS.d/next/Library/2025-05-18-13-23-29.gh-issue-134168.hgx3Xg.rst
new file mode 100644
index 00000000000000..5a0e20005db11e
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-05-18-13-23-29.gh-issue-134168.hgx3Xg.rst
@@ -0,0 +1,2 @@
+:mod:`http.server`: Fix IPv6 address binding and
+:option:`--directory <http.server --directory>` handling when using HTTPS.

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: arch...@mail-archive.com

Reply via email to