mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
[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:
parent
162e3f3511
commit
81f099375e
2 changed files with 13 additions and 4 deletions
|
@ -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,
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
:mod:`http.server`: Fix IPv6 address binding and
|
||||
:option:`--directory <http.server --directory>` handling when using HTTPS.
|
Loading…
Add table
Add a link
Reference in a new issue