net.http: support passing on_running, on_stopped, on_closed callback functions to http.Server{}, as well as show_startup_message: false. (#19591)

This commit is contained in:
Delyan Angelov 2023-10-18 09:00:42 +03:00 committed by GitHub
parent 69d62e458b
commit 0a89f3082d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 172 additions and 27 deletions

View file

@ -22,7 +22,17 @@ mut:
is_blocking bool
}
pub fn dial_tcp(address string) !&TcpConn {
pub fn dial_tcp(oaddress string) !&TcpConn {
mut address := oaddress
$if windows {
// resolving 0.0.0.0 to localhost, works on linux and macos, but not on windows, so try to emulate it:
if address.starts_with(':::') {
address = address.replace_once(':::', 'localhost:')
}
if address.starts_with('0.0.0.0:') {
address = address.replace_once('0.0.0.0:', 'localhost:')
}
}
addrs := resolve_addrs_fuzzy(address, .tcp) or {
return error('${err.msg()}; could not resolve address ${address} in dial_tcp')
}