]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-134168: fix `http.server` CLI support for IPv6 and `--directory` when serving...
authorggqlq <124190229+ggqlq@users.noreply.github.com>
Sat, 24 May 2025 12:19:20 +0000 (20:19 +0800)
committerGitHub <noreply@github.com>
Sat, 24 May 2025 12:19:20 +0000 (12:19 +0000)
Lib/http/server.py
Misc/NEWS.d/next/Library/2025-05-18-13-23-29.gh-issue-134168.hgx3Xg.rst [new file with mode: 0644]

index f6d1b998f4201ed471881b5597e4a3b5693d4a68..ef10d1859326339e6269bf42d89cee3b5edbc11e 100644 (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,
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 (file)
index 0000000..5a0e200
--- /dev/null
@@ -0,0 +1,2 @@
+:mod:`http.server`: Fix IPv6 address binding and
+:option:`--directory <http.server --directory>` handling when using HTTPS.