MCPcopy
hub / github.com/gofiber/fiber / normalizeSchemeHost

Function normalizeSchemeHost

internal/schemehost/schemehost.go:31–56  ·  view source on GitHub ↗
(scheme, host string)

Source from the content-addressed store, hash-verified

29}
30
31func normalizeSchemeHost(scheme, host string) string {
32 host = utilsstrings.ToLower(host)
33
34 var defaultPort string
35 switch scheme {
36 case schemeHTTP:
37 defaultPort = "80"
38 case schemeHTTPS:
39 defaultPort = "443"
40 default:
41 return host
42 }
43
44 // Fast path for a clean "host" or "host:port" value (the common case),
45 // avoiding the url.Parse allocation. Anything unusual (userinfo, path,
46 // percent-encoding, bracketed IPv6, control chars, empty/invalid port, ...)
47 // falls back to the url.Parse path, which preserves the exact legacy behavior.
48 if hasPort, clean := classifyHostPort(host); clean {
49 if hasPort {
50 return host
51 }
52 return host + ":" + defaultPort
53 }
54
55 return normalizeSchemeHostViaParse(scheme, host, defaultPort)
56}
57
58// classifyHostPort reports whether host is a plain "<reg-name-or-IPv4>" or
59// "<reg-name-or-IPv4>:<port>" value (clean) and, if so, whether it carries an

Callers 5

MatchFunction · 0.85
Test_normalizeSchemeHostFunction · 0.85
FuzzNormalizeSchemeHostFunction · 0.85

Calls 2

classifyHostPortFunction · 0.85