Documentation ¶
Index ¶
- Variables
- type EmptyParserOption
- type IPv4Addr
- type IPv6Addr
- type NameValuePair
- type Parser
- type ParserOption
- func WithAcceptInvalidCodepoints() ParserOption
- func WithAllowSettingPathForNonBaseUrl() ParserOption
- func WithCollapseConsecutiveSlashes() ParserOption
- func WithEncodingOverride(cm *charmap.Charmap) ParserOption
- func WithFailOnValidationError() ParserOption
- func WithFragmentPathPercentEncodeSet(encodeSet *PercentEncodeSet) ParserOption
- func WithLaxHostParsing() ParserOption
- func WithPathPercentEncodeSet(encodeSet *PercentEncodeSet) ParserOption
- func WithPercentEncodeSinglePercentSign() ParserOption
- func WithPostParseHostFunc(f func(url *Url, host string) string) ParserOption
- func WithPreParseHostFunc(f func(url *Url, host string) string) ParserOption
- func WithQueryPercentEncodeSet(encodeSet *PercentEncodeSet) ParserOption
- func WithReportValidationErrors() ParserOption
- func WithSkipTrailingSlashNormalization() ParserOption
- func WithSkipWindowsDriveLetterNormalization() ParserOption
- func WithSpecialFragmentPathPercentEncodeSet(encodeSet *PercentEncodeSet) ParserOption
- func WithSpecialQueryPercentEncodeSet(encodeSet *PercentEncodeSet) ParserOption
- func WithSpecialSchemes(special map[string]string) ParserOption
- type PercentEncodeSet
- func (p *PercentEncodeSet) ByteShouldBeEncoded(b byte) bool
- func (p *PercentEncodeSet) Clear(bytes ...uint) *PercentEncodeSet
- func (p *PercentEncodeSet) RuneNotInSet(r rune) bool
- func (p *PercentEncodeSet) RuneShouldBeEncoded(r rune) bool
- func (p *PercentEncodeSet) Set(bytes ...uint) *PercentEncodeSet
- type Url
- func (u *Url) DecodedPort() int
- func (u *Url) Fragment() string
- func (u *Url) Hash() string
- func (u *Url) Host() string
- func (u *Url) Hostname() string
- func (u *Url) Href(excludeFragment bool) string
- func (u *Url) IsIPv4() bool
- func (u *Url) IsIPv6() bool
- func (u *Url) IsSpecialScheme() bool
- func (u *Url) Parse(ref string) (*Url, error)
- func (u *Url) Password() string
- func (u *Url) Pathname() string
- func (u *Url) Port() string
- func (u *Url) Protocol() string
- func (u *Url) Query() string
- func (u *Url) Scheme() string
- func (u *Url) Search() string
- func (u *Url) SearchParams() *searchParams
- func (u *Url) SetHash(fragment string)
- func (u *Url) SetHost(host string)
- func (u *Url) SetHostname(host string)
- func (u *Url) SetPassword(password string)
- func (u *Url) SetPathname(path string)
- func (u *Url) SetPort(port string)
- func (u *Url) SetProtocol(scheme string)
- func (u *Url) SetSearch(query string)
- func (u *Url) SetUsername(username string)
- func (u *Url) String() string
- func (u *Url) Username() string
- func (u *Url) ValidationErrors() []error
Constants ¶
This section is empty.
Variables ¶
var ASCIIAlpha = bitset.New(0x7a)
var ASCIIAlphanumeric = bitset.New(0x7a)
var ASCIIDigit = bitset.New(0x39)
var ASCIIHexDigit = bitset.New(0x66)
var ASCIITabOrNewline = bitset.New(0x0d).Set(0x09).Set(0x0a).Set(0x0d)
var C0OrSpacePercentEncodeSet = NewPercentEncodeSet(0x21)
var C0PercentEncodeSet = NewPercentEncodeSet(0x20)
var ForbiddenHostCodePoint = bitset.New(0x5d).Set(0x00).Set(0x09).Set(0x0a).Set(0x0d).Set(0x20).
Set(0x23).Set(0x25).Set(0x2f).Set(0x3a).Set(0x3c).Set(0x3e).Set(0x3f).Set(0x40).Set(0x5b).
Set(0x5c).Set(0x5d).Set(0x5e)
var FragmentPercentEncodeSet = C0OrSpacePercentEncodeSet.Set(0x22, 0x3c, 0x3e, 0x60)
var HostPercentEncodeSet = C0OrSpacePercentEncodeSet.Set(0x23)
var PathPercentEncodeSet = QueryPercentEncodeSet.Set(0x3f, 0x60, 0x7b, 0x7d)
var QueryPercentEncodeSet = C0OrSpacePercentEncodeSet.Set(0x22, 0x23, 0x3C, 0x3E)
var SpecialQueryPercentEncodeSet = QueryPercentEncodeSet.Set(0x27)
var UserInfoPercentEncodeSet = PathPercentEncodeSet.Set(0x2f, 0x3a, 0x3b, 0x3d, 0x40, 0x5b, 0x5c, 0x5d, 0x5e, 0x7c)
Functions ¶
This section is empty.
Types ¶
type EmptyParserOption ¶
type EmptyParserOption struct{}
EmptyParserOption does not alter the parser configuration. It can be embedded in another structure to build custom parser options.
type NameValuePair ¶
type NameValuePair struct {
Name, Value string
}
type Parser ¶
type Parser interface { Parse(rawUrl string) (*Url, error) ParseRef(rawUrl, ref string) (*Url, error) }
func NewParser ¶
func NewParser(opts ...ParserOption) Parser
type ParserOption ¶
type ParserOption interface {
// contains filtered or unexported methods
}
ParserOption configures how we parse a URL.
func WithAcceptInvalidCodepoints ¶
func WithAcceptInvalidCodepoints() ParserOption
WithAcceptInvalidCodepoints percent encodes values which are not valid UTF-8.
This API is EXPERIMENTAL.
func WithAllowSettingPathForNonBaseUrl ¶
func WithAllowSettingPathForNonBaseUrl() ParserOption
WithAllowSettingPathForNonBaseUrl allows to set path for a url which cannot be a base url. WhathWg standard says this should be illegal
This API is EXPERIMENTAL.
func WithCollapseConsecutiveSlashes ¶
func WithCollapseConsecutiveSlashes() ParserOption
WithCollapseConsecutiveSlashes collapses consecutive slashes in path into one (e.g. http://example.com//foo///bar => http://example.com/foo/bar).
func WithEncodingOverride ¶
func WithEncodingOverride(cm *charmap.Charmap) ParserOption
WithEncodingOverride allows to set an encoding other than UTF-8 when parsing.
This API is EXPERIMENTAL.
func WithFailOnValidationError ¶
func WithFailOnValidationError() ParserOption
WithFailOnValidationError makes the parser throw an error on non fatal validation errors.
func WithFragmentPathPercentEncodeSet ¶
func WithFragmentPathPercentEncodeSet(encodeSet *PercentEncodeSet) ParserOption
WithFragmentPathPercentEncodeSet allows to set an alternative set of characters to percent encode in fragment component when scheme is not special.
This API is EXPERIMENTAL.
func WithLaxHostParsing ¶
func WithLaxHostParsing() ParserOption
WithLaxHostParsing ignores some decoding errors and returns the host as is.
This API is EXPERIMENTAL.
func WithPathPercentEncodeSet ¶
func WithPathPercentEncodeSet(encodeSet *PercentEncodeSet) ParserOption
WithPathPercentEncodeSet allows to set an alternative set of characters to percent encode in path component.
This API is EXPERIMENTAL.
func WithPercentEncodeSinglePercentSign ¶
func WithPercentEncodeSinglePercentSign() ParserOption
WithPercentEncodeSinglePercentSign percent encodes a '%' which is not followed by two hexadecimal digits instead of complaining about invalid percent encoding.
This API is EXPERIMENTAL.
func WithPostParseHostFunc ¶
func WithPostParseHostFunc(f func(url *Url, host string) string) ParserOption
WithPostParseHostFunc is a function which allows manipulation of host string after it is parsed. It is called only if the host isn't an IP address.
This API is EXPERIMENTAL.
func WithPreParseHostFunc ¶
func WithPreParseHostFunc(f func(url *Url, host string) string) ParserOption
WithPreParseHostFunc is a function which allows manipulation of host string before it is parsed.
This API is EXPERIMENTAL.
func WithQueryPercentEncodeSet ¶
func WithQueryPercentEncodeSet(encodeSet *PercentEncodeSet) ParserOption
WithQueryPercentEncodeSet allows to set an alternative set of characters to percent encode in query component when scheme is not special.
This API is EXPERIMENTAL.
func WithReportValidationErrors ¶
func WithReportValidationErrors() ParserOption
WithReportValidationErrors records all non fatal validation errors so that they can be fetchd by a call to....
func WithSkipTrailingSlashNormalization ¶
func WithSkipTrailingSlashNormalization() ParserOption
WithSkipTrailingSlashNormalization skips normalizing of empty paths.
This API is EXPERIMENTAL.
func WithSkipWindowsDriveLetterNormalization ¶
func WithSkipWindowsDriveLetterNormalization() ParserOption
WithSkipWindowsDriveLetterNormalization skips conversion of 'C|' to 'C:'. WhathWg standard says only a normalized Windows drive letter is conforming.
This API is EXPERIMENTAL.
func WithSpecialFragmentPathPercentEncodeSet ¶
func WithSpecialFragmentPathPercentEncodeSet(encodeSet *PercentEncodeSet) ParserOption
WithSpecialFragmentPathPercentEncodeSet allows to set an alternative set of characters to percent encode in fragment component when scheme is special.
This API is EXPERIMENTAL.
func WithSpecialQueryPercentEncodeSet ¶
func WithSpecialQueryPercentEncodeSet(encodeSet *PercentEncodeSet) ParserOption
WithSpecialQueryPercentEncodeSet allows to set an alternative set of characters to percent encode in query component when scheme is special.
This API is EXPERIMENTAL.
func WithSpecialSchemes ¶
func WithSpecialSchemes(special map[string]string) ParserOption
WithSpecialSchemes allows overriding the notion of special schemes. special is a map of 'scheme' => 'default port'
WhatWg standard removed gopher from special schemes. This is how you add it back:
special := map[string]string{ "ftp": "21", "file": "", "http": "80", "https": "443", "ws": "80", "wss": "443", "gopher": "70", }
This API is EXPERIMENTAL.
type PercentEncodeSet ¶
type PercentEncodeSet struct {
// contains filtered or unexported fields
}
func NewPercentEncodeSet ¶
func NewPercentEncodeSet(allBelow int32, bytes ...uint) *PercentEncodeSet
func (*PercentEncodeSet) ByteShouldBeEncoded ¶
func (p *PercentEncodeSet) ByteShouldBeEncoded(b byte) bool
func (*PercentEncodeSet) Clear ¶
func (p *PercentEncodeSet) Clear(bytes ...uint) *PercentEncodeSet
func (*PercentEncodeSet) RuneNotInSet ¶
func (p *PercentEncodeSet) RuneNotInSet(r rune) bool
func (*PercentEncodeSet) RuneShouldBeEncoded ¶
func (p *PercentEncodeSet) RuneShouldBeEncoded(r rune) bool
func (*PercentEncodeSet) Set ¶
func (p *PercentEncodeSet) Set(bytes ...uint) *PercentEncodeSet
type Url ¶
type Url struct {
// contains filtered or unexported fields
}
func (*Url) DecodedPort ¶
func (*Url) Hash ¶
Hash implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) Host ¶
Host implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) Hostname ¶
Hostname implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) Href ¶
Href implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) IsSpecialScheme ¶
func (*Url) Password ¶
Password implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) Pathname ¶
Pathname implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) Port ¶
Port implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) Protocol ¶
Protocol implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) Search ¶
Search implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) SearchParams ¶
func (u *Url) SearchParams() *searchParams
SearchParams implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) SetHash ¶
SetHash implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) SetHost ¶
SetHost implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) SetHostname ¶
SetHostname implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) SetPassword ¶
SetPassword implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) SetPathname ¶
SetPathname implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) SetPort ¶
SetPort implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) SetProtocol ¶
SetProtocol implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) SetSearch ¶
SetSearch implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) SetUsername ¶
SetUsername implements WHATWG url api (https://url.spec.whatwg.org/#api)
func (*Url) Username ¶
Username implements WHATWG url api (https://url.spec.whatwg.org/#api)