[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 2fd09b0110)

Co-authored-by: ggqlq <124190229+ggqlq@users.noreply.github.com>
This commit is contained in:
Bénédikt Tran 2025-05-24 15:34:31 +02:00 committed by GitHub
parent 162e3f3511
commit 81f099375e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View file

@ -1320,8 +1320,8 @@ def test(HandlerClass=BaseHTTPRequestHandler,
HandlerClass.protocol_version = protocol HandlerClass.protocol_version = protocol
if tls_cert: if tls_cert:
server = ThreadingHTTPSServer(addr, HandlerClass, certfile=tls_cert, server = ServerClass(addr, HandlerClass, certfile=tls_cert,
keyfile=tls_key, password=tls_password) keyfile=tls_key, password=tls_password)
else: else:
server = ServerClass(addr, HandlerClass) server = ServerClass(addr, HandlerClass)
@ -1387,7 +1387,7 @@ if __name__ == '__main__':
handler_class = SimpleHTTPRequestHandler handler_class = SimpleHTTPRequestHandler
# ensure dual-stack is not disabled; ref #38907 # ensure dual-stack is not disabled; ref #38907
class DualStackServer(ThreadingHTTPServer): class DualStackServerMixin:
def server_bind(self): def server_bind(self):
# suppress exception when protocol is IPv4 # suppress exception when protocol is IPv4
@ -1400,9 +1400,16 @@ if __name__ == '__main__':
self.RequestHandlerClass(request, client_address, self, self.RequestHandlerClass(request, client_address, self,
directory=args.directory) directory=args.directory)
class HTTPDualStackServer(DualStackServerMixin, ThreadingHTTPServer):
pass
class HTTPSDualStackServer(DualStackServerMixin, ThreadingHTTPSServer):
pass
ServerClass = HTTPSDualStackServer if args.tls_cert else HTTPDualStackServer
test( test(
HandlerClass=handler_class, HandlerClass=handler_class,
ServerClass=DualStackServer, ServerClass=ServerClass,
port=args.port, port=args.port,
bind=args.bind, bind=args.bind,
protocol=args.protocol, 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.