-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Improved URL display on MOTD #2817
base: main
Are you sure you want to change the base?
Conversation
…t port number if standard.
Setting |
Maybe also time to handle the whole server name issue. 😉 |
# colon(:) is legal for a host only in an ipv6 address | ||
url_host = f"[{host}]" if ":" in host else host | ||
url_port = ( | ||
"" | ||
if ( | ||
(proto == "https" and port == 443) | ||
or (proto == "http" and port == 80) | ||
) | ||
else f":{port}" | ||
) | ||
|
||
special = { | ||
"127.0.0.1": "IPv4", | ||
"0.0.0.0": "IPv4 wildcard", | ||
"::1": "IPv6", | ||
"::": "IPv6 wildcard", | ||
}.get(host, "") | ||
if special: | ||
return f"({special}) {proto}://localhost{url_port}" | ||
|
||
return serve_location | ||
return f"{proto}://{url_host}{url_port}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole bit feels to me like logic we should probably abstract to a utility function somewhere. Don't we do this elsewhere also?
That's a can of worms, for sure. Would be useful to first identify all the problems that we are solving here, and things affected by them.
What'd I miss? |
Sanic would use any host setting for URL construction. This PR fixes the common cases of normal localhost and wildcard addresses, for which we instead display localhost. Similarly for UNIX sockets, as that format works e.g. with curl. URL to wildcard doesn't work at all, and connecting localhost by IP rather than domain name can be problematic with TLS if not otherwise.
Additionally, hides the port number if standard ports are used.