Package webutil implements utility routines for web-related operations and applications.
Package Files ¶
func CanonicalizeHost ¶
func CanonicalizeHost(hostName, defaultDomain, defaultPort string) (protocol, fqhp, fqh, host, domain, port string, hosterr error)
CanonicalizeHost accepts a server host name as typically encountered by web server and generally obtained from the http request Host header field and canonicalizes it into: fqhp - fully qualified host+domain with a port - ie: host.domain:port fqh - fully qualified host+domain without a port - ie: host.domain host - the hostname, i.e. the first component of a . separated name domain - the second and subsequent components of a . separated name port - the port.
It is generally used for constructing redirects, determine/scoping cookie names etc.
The server name can be in any of the forms accepted by a web browser: 1. [<protocol>://]<ip-addr>[:port] 2. [<protocol>://]<name>[:<port>] 3. [<protocol>://]<name>[.<subdomain>]+[:<port>] The defaultDomain and defaultPort, if not "", will be used if there is no domain or port in hostName.