url

package
Version: v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: Apache-2.0 Imports: 12 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ASCIIAlpha = bitset.New(0x7a)
View Source
var ASCIIAlphanumeric = bitset.New(0x7a)
View Source
var ASCIIDigit = bitset.New(0x39)
View Source
var ASCIIHexDigit = bitset.New(0x66)
View Source
var ASCIITabOrNewline = bitset.New(0x0d).Set(0x09).Set(0x0a).Set(0x0d)
View Source
var C0OrSpacePercentEncodeSet = NewPercentEncodeSet(0x21)
View Source
var C0PercentEncodeSet = NewPercentEncodeSet(0x20)
View Source
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)
View Source
var FragmentPercentEncodeSet = C0OrSpacePercentEncodeSet.Set(0x22, 0x3c, 0x3e, 0x60)
View Source
var HostPercentEncodeSet = C0OrSpacePercentEncodeSet.Set(0x23)
View Source
var PathPercentEncodeSet = QueryPercentEncodeSet.Set(0x3f, 0x60, 0x7b, 0x7d)
View Source
var QueryPercentEncodeSet = C0OrSpacePercentEncodeSet.Set(0x22, 0x23, 0x3C, 0x3E)
View Source
var SpecialQueryPercentEncodeSet = QueryPercentEncodeSet.Set(0x27)
View Source
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 IPv4Addr

type IPv4Addr uint32

func (*IPv4Addr) String

func (address *IPv4Addr) String() string

type IPv6Addr

type IPv6Addr [8]uint16

func (*IPv6Addr) String

func (address *IPv6Addr) String() string

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 Parse

func Parse(rawUrl string) (*Url, error)

func ParseRef

func ParseRef(rawUrl, ref string) (*Url, error)

func (*Url) DecodedPort

func (u *Url) DecodedPort() int

func (*Url) Fragment

func (u *Url) Fragment() string

func (*Url) Hash

func (u *Url) Hash() string

Hash implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) Host

func (u *Url) Host() string

Host implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) Hostname

func (u *Url) Hostname() string

Hostname implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) Href

func (u *Url) Href(excludeFragment bool) string

Href implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) IsIPv4

func (u *Url) IsIPv4() bool

func (*Url) IsIPv6

func (u *Url) IsIPv6() bool

func (*Url) IsSpecialScheme

func (u *Url) IsSpecialScheme() bool

func (*Url) Parse

func (u *Url) Parse(ref string) (*Url, error)

func (*Url) Password

func (u *Url) Password() string

Password implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) Pathname

func (u *Url) Pathname() string

Pathname implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) Port

func (u *Url) Port() string

Port implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) Protocol

func (u *Url) Protocol() string

Protocol implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) Query

func (u *Url) Query() string

func (*Url) Scheme

func (u *Url) Scheme() string

func (*Url) Search

func (u *Url) Search() string

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

func (u *Url) SetHash(fragment string)

SetHash implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) SetHost

func (u *Url) SetHost(host string)

SetHost implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) SetHostname

func (u *Url) SetHostname(host string)

SetHostname implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) SetPassword

func (u *Url) SetPassword(password string)

SetPassword implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) SetPathname

func (u *Url) SetPathname(path string)

SetPathname implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) SetPort

func (u *Url) SetPort(port string)

SetPort implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) SetProtocol

func (u *Url) SetProtocol(scheme string)

SetProtocol implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) SetSearch

func (u *Url) SetSearch(query string)

SetSearch implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) SetUsername

func (u *Url) SetUsername(username string)

SetUsername implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) String

func (u *Url) String() string

func (*Url) Username

func (u *Url) Username() string

Username implements WHATWG url api (https://url.spec.whatwg.org/#api)

func (*Url) ValidationErrors

func (u *Url) ValidationErrors() []error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL