Documentation ¶
Index ¶
- func CleanHost(in string) string
- func ParseHostPort(scheme string, hostport string, ...) (host, port string, err error)
- func ParseStandardURL(rawUrl string) (*url.URL, error)
- func ParseURL(rawUrl string, getDefaultPort func(schema string) (string, error)) (u *url.URL, host string, port int, err error)
- func RemoveZone(host string) string
- func ResolveWithTarget(ctx context.Context, u *url.URL, target string) (*url.URL, error)
- type Proto
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CleanHost ¶
cleanHost cleans up the host sent in request's Host header.
It both strips anything after '/' or ' ', and puts the value into Punycode form, if necessary.
Ideally we'd clean the Host header according to the spec:
https://tools.ietf.org/html/rfc7230#section-5.4 (Host = uri-host [ ":" port ]") https://tools.ietf.org/html/rfc7230#section-2.7 (uri-host -> rfc3986's host) https://tools.ietf.org/html/rfc3986#section-3.2.2 (definition of host)
But practically, what we are trying to avoid is the situation in issue 11206, where a malformed Host header used in the proxy context would create a bad request. So it is enough to just truncate at the first offending character.
func ParseHostPort ¶
func ParseHostPort(scheme string, hostport string, getDefaultPort func(schema string) (string, error)) (host, port string, err error)
ParseHostPort takes the user input target string, returns formatted host and port info. If target doesn't specify a port, set the port to be the defaultPort. If target is in IPv6 format and host-name is enclosed in sqarue brackets, brackets are strippd when setting the host. examples: target: "www.google.com" returns host: "www.google.com", port: "443" target: "ipv4-host:80" returns host: "ipv4-host", port: "80" target: "[ipv6-host]" returns host: "ipv6-host", port: "443" target: ":80" returns host: "localhost", port: "80" target: ":" returns host: "localhost", port: "443"
func RemoveZone ¶
removeZone removes IPv6 zone identifier from host. E.g., "[fe80::1%en0]:8080" to "[fe80::1]:8080"