]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-134168: fix `http.server` CLI support for IPv6 and `--directory` when servi...
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Sat, 24 May 2025 13:34:31 +0000 (15:34 +0200)
committerGitHub <noreply@github.com>
Sat, 24 May 2025 13:34:31 +0000 (15:34 +0200)
[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 <124190229+ggqlq@users.noreply.github.com>
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 31fe9cae781f0af4e992ccb0effad7912d76419c..dda32644a28f9038426d17da4e94fd54c19ac336 100644 (file)
@@ -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 @@ if __name__ == '__main__':
         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 @@ if __name__ == '__main__':
             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 (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.