Add support for IPv6

http.server supports IPv6, but the address has to be processed by _get_best_family
This commit is contained in:
chaihahaha 2025-02-23 02:13:11 +08:00 committed by GitHub
parent 09b641aaa7
commit 12d1e968cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -8,7 +8,7 @@ import time
import uuid import uuid
import warnings import warnings
from dataclasses import dataclass, field from dataclasses import dataclass, field
from http.server import BaseHTTPRequestHandler, HTTPServer from http.server import BaseHTTPRequestHandler, HTTPServer, _get_best_family
from pathlib import Path from pathlib import Path
from typing import ( from typing import (
Any, Any,
@ -694,6 +694,7 @@ def run(
): ):
server_address = (host, port) server_address = (host, port)
prompt_cache = PromptCache() prompt_cache = PromptCache()
server_class.address_family, server_address = _get_best_family(*server_address)
httpd = server_class( httpd = server_class(
server_address, server_address,
lambda *args, **kwargs: handler_class( lambda *args, **kwargs: handler_class(