Skip to content

Commit 81f0993

Browse files
picnixzggqlq
andauthored
[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 2fd09b0) Co-authored-by: ggqlq <124190229+ggqlq@users.noreply.github.com>
1 parent 162e3f3 commit 81f0993

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

Lib/http/server.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,8 +1320,8 @@ def test(HandlerClass=BaseHTTPRequestHandler,
13201320
HandlerClass.protocol_version = protocol
13211321

13221322
if tls_cert:
1323-
server = ThreadingHTTPSServer(addr, HandlerClass, certfile=tls_cert,
1324-
keyfile=tls_key, password=tls_password)
1323+
server = ServerClass(addr, HandlerClass, certfile=tls_cert,
1324+
keyfile=tls_key, password=tls_password)
13251325
else:
13261326
server = ServerClass(addr, HandlerClass)
13271327

@@ -1387,7 +1387,7 @@ def test(HandlerClass=BaseHTTPRequestHandler,
13871387
handler_class = SimpleHTTPRequestHandler
13881388

13891389
# ensure dual-stack is not disabled; ref #38907
1390-
class DualStackServer(ThreadingHTTPServer):
1390+
class DualStackServerMixin:
13911391

13921392
def server_bind(self):
13931393
# suppress exception when protocol is IPv4
@@ -1400,9 +1400,16 @@ def finish_request(self, request, client_address):
14001400
self.RequestHandlerClass(request, client_address, self,
14011401
directory=args.directory)
14021402

1403+
class HTTPDualStackServer(DualStackServerMixin, ThreadingHTTPServer):
1404+
pass
1405+
class HTTPSDualStackServer(DualStackServerMixin, ThreadingHTTPSServer):
1406+
pass
1407+
1408+
ServerClass = HTTPSDualStackServer if args.tls_cert else HTTPDualStackServer
1409+
14031410
test(
14041411
HandlerClass=handler_class,
1405-
ServerClass=DualStackServer,
1412+
ServerClass=ServerClass,
14061413
port=args.port,
14071414
bind=args.bind,
14081415
protocol=args.protocol,
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
:mod:`http.server`: Fix IPv6 address binding and
2+
:option:`--directory <http.server --directory>` handling when using HTTPS.

0 commit comments

Comments
 (0)