SiteFor
#func SiteFor(host: str, port: int): intThe index of the site that answers a host name on a port, or -1 when none does. The name is lower-cased and a trailing port or dot is ignored. An exact name wins over a wildcard, and a name nobody listed falls back to the default site of that port.
import net.httpd
func main:
text := `
server:
site:
listen = 8080
names = "example.test *.example.test"
location "/assets/": cache = 30d end
location "= /health": return = 200 "ok" end
location "^~ /static/": cache = 1h end
location "~ \.php$": return = 403 "no" end
end
site:
listen = 8080
names = "other.test"
default = true
end
end
`
println httpd.LoadText(text, "match.salam"), httpd.ProblemCount()
println httpd.SiteCount(), httpd.SiteNames(0), httpd.SiteNames(1)
println httpd.SiteFor("example.test", 8080),
httpd.SiteFor("API.Example.Test:8080", 8080),
httpd.SiteFor("other.test.", 8080)
println httpd.SiteFor("unknown.test", 8080), httpd.SiteFor("example.test", 9090)
println httpd.LocationPattern(httpd.LocationFor(0, "/health"))
println httpd.LocationPattern(httpd.LocationFor(0, "/assets/logo.png"))
println httpd.LocationPattern(httpd.LocationFor(0, "/static/a.php"))
println httpd.LocationPattern(httpd.LocationFor(0, "/x/index.php"))
println httpd.LocationFor(0, "/plain"), httpd.LocationFor(1, "/anything")
endtrue 0 2 example.test *.example.test other.test 0 0 1 1 -1 /health /assets/ /static/ \.php$ -1 -1