https://github.com/python/cpython/commit/81f099375e3007709e3668e603edd188c05d662d
commit: 81f099375e3007709e3668e603edd188c05d662d
branch: 3.14
author: Bénédikt Tran <[email protected]>
committer: picnixz <[email protected]>
date: 2025-05-24T15:34:31+02:00
summary:

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

[3.14] gh-134168: fix `http.server` CLI support for IPv6 and `--directory` when 
serving over HTTPS (GH-134169)
(cherry picked from commit 2fd09b011031f3c00c342b44e02e2817010e507c)

Co-authored-by: ggqlq <[email protected]>

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 31fe9cae781f0a..dda32644a28f90 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -1320,8 +1320,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)
 
@@ -1387,7 +1387,7 @@ def test(HandlerClass=BaseHTTPRequestHandler,
         handler_class = SimpleHTTPRequestHandler
 
     # ensure dual-stack is not disabled; ref #38907
-    class DualStackServer(ThreadingHTTPServer):
+    class DualStackServerMixin:
 
         def server_bind(self):
             # suppress exception when protocol is IPv4
@@ -1400,9 +1400,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=handler_class,
-        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 -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to