Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-24209: In http.server script, rely on getaddrinfo to bind to preferred address based on the bind parameter. #11767

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 8 commits into from
Feb 7, 2019
Prev Previous commit
In getaddrinfo, use AI_PASSIVE to indicate to get the wildcard addres…
…s (all interfaces).
  • Loading branch information
jaraco committed Feb 6, 2019
commit 62dbe55c9d88c75868399de9d86bcd947e23951c
16 changes: 9 additions & 7 deletions 16 Lib/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -1224,10 +1224,14 @@ def run_cgi(self):
self.log_message("CGI script exited OK")


def _get_best_family(address):
infos = socket.getaddrinfo(*address, type=socket.SOCK_STREAM)
def _get_best_family(*address):
infos = socket.getaddrinfo(
*address,
type=socket.SOCK_STREAM,
flags=socket.AI_PASSIVE,
)
family, type, proto, canonname, sockaddr = next(iter(infos))
return family
return family, sockaddr


def test(HandlerClass=BaseHTTPRequestHandler,
Expand All @@ -1238,12 +1242,10 @@ def test(HandlerClass=BaseHTTPRequestHandler,
This runs an HTTP server on port 8000 (or the port argument).

"""
server_address = (bind, port)

ServerClass.address_family = _get_best_family(server_address)
ServerClass.address_family, addr = _get_best_family(bind, port)

HandlerClass.protocol_version = protocol
with ServerClass(server_address, HandlerClass) as httpd:
with ServerClass(addr, HandlerClass) as httpd:
host, port = httpd.socket.getsockname()[:2]
url_host = f'[{host}]' if ':' in host else host
print(
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.