url

package
v1.2.118 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanHost

func CleanHost(in string) string

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 ParseStandardURL

func ParseStandardURL(rawUrl string) (*url.URL, error)

func ParseURL

func ParseURL(rawUrl string, getDefaultPort func(schema string) (string, error)) (u *url.URL, host string, port int, err error)

func RemoveZone

func RemoveZone(host string) string

removeZone removes IPv6 zone identifier from host. E.g., "[fe80::1%en0]:8080" to "[fe80::1]:8080"

func ResolveWithTarget

func ResolveWithTarget(ctx context.Context, u *url.URL, target string) (*url.URL, error)

ResolveWithTarget reset Host in url.Url by resolver.Target ResolveWithTarget always returns a new URL instance, even if the returned URL is identical to either the base or reference.

Types

type Proto

type Proto struct {
	Type  string // "RTSP"
	Major int    // 1
	Minor int    // 0
}

func ParseProto

func ParseProto(rawproto string) (*Proto, error)

func (*Proto) ProtoAtLeast

func (p *Proto) ProtoAtLeast(major, minor int) bool

func (*Proto) String

func (p *Proto) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL