Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:mod:`http.server`: Fix IPv6 address binding and
:option:`--directory <http.server --directory>` handling when using HTTPS.
Loading