Back to Pocketbase

Interface URL

static/jsvm/interfaces/url.URL.html

latest8.0 KB
Original Source

Interface URL

A URL represents a parsed URL (technically, a URI reference).

The general form represented is:

[scheme:][//[userinfo@]host][/]path[?query][#fragment]Copy

URLs that do not start with a slash after the scheme are interpreted as:

scheme:opaque[?query][#fragment]Copy

The Host field contains the host and port subcomponents of the URL. When the port is present, it is separated from the host with a colon. When the host is an IPv6 address, it must be enclosed in square brackets: "[fe80::1]:80". The [net.JoinHostPort] function combines a host and port into a string suitable for the Host field, adding square brackets to the host when necessary.

Note that the Path field is stored in decoded form: /%47%6f%2f becomes /Go/. A consequence is that it is impossible to tell which slashes in the Path were slashes in the raw URL and which were %2f. This distinction is rarely important, but when it is, the code should use the [URL.EscapedPath] method, which preserves the original encoding of Path.

The RawPath field is an optional field which is only set when the default encoding of Path is different from the escaped path. See the EscapedPath method for more details.

URL's String method uses the EscapedPath method to obtain the path.

Hierarchy

  • URL

Index

Methods

appendBinaryescapedFragmentescapedPathhostnameisAbsjoinPathmarshalBinaryparseportqueryredactedrequestURIresolveReferencestringunmarshalBinary

Properties

forceQueryfragmenthostomitHostopaquepathrawFragmentrawPathrawQueryschemeuser?

Methods

appendBinary

  • appendBinary(b): string | number[]

Parameters

b: string | number[]

Returns string | number[]

escapedFragment

  • escapedFragment(): string

EscapedFragment returns the escaped form of u.Fragment. In general there are multiple possible escaped forms of any fragment. EscapedFragment returns u.RawFragment when it is a valid escaping of u.Fragment. Otherwise EscapedFragment ignores u.RawFragment and computes an escaped form on its own. The [URL.String] method uses EscapedFragment to construct its result. In general, code should call EscapedFragment instead of reading u.RawFragment directly.

Returns string

escapedPath

  • escapedPath(): string

EscapedPath returns the escaped form of u.Path. In general there are multiple possible escaped forms of any path. EscapedPath returns u.RawPath when it is a valid escaping of u.Path. Otherwise EscapedPath ignores u.RawPath and computes an escaped form on its own. The [URL.String] and [URL.RequestURI] methods use EscapedPath to construct their results. In general, code should call EscapedPath instead of reading u.RawPath directly.

Returns string

hostname

  • hostname(): string

Hostname returns u.Host, stripping any valid port number if present.

If the result is enclosed in square brackets, as literal IPv6 addresses are, the square brackets are removed from the result.

Returns string

isAbs

  • isAbs(): boolean

IsAbs reports whether the [URL] is absolute. Absolute means that it has a non-empty scheme.

Returns boolean

joinPath

  • joinPath(...elem): URL

JoinPath returns a new [URL] with the provided path elements joined to any existing path and the resulting path cleaned of any ./ or ../ elements. Any sequences of multiple / characters will be reduced to a single /.

Parameters

Rest ...elem: string[]

Returns URL

marshalBinary

  • marshalBinary(): string | number[]

Returns string | number[]

parse

  • parse(ref): URL

Parse parses a [URL] in the context of the receiver. The provided URL may be relative or absolute. Parse returns nil, err on parse failure, otherwise its return value is the same as [URL.ResolveReference].

Parameters

ref: string

Returns URL

port

  • port(): string

Port returns the port part of u.Host, without the leading colon.

If u.Host doesn't contain a valid numeric port, Port returns an empty string.

Returns string

query

Query parses RawQuery and returns the corresponding values. It silently discards malformed value pairs. To check errors use [ParseQuery].

Returns Values

redacted

  • redacted(): string

Redacted is like [URL.String] but replaces any password with "xxxxx". Only the password in u.User is redacted.

Returns string

requestURI

  • requestURI(): string

RequestURI returns the encoded path?query or opaque?query string that would be used in an HTTP request for u.

Returns string

resolveReference

  • resolveReference(ref): URL

ResolveReference resolves a URI reference to an absolute URI from an absolute base URI u, per RFC 3986 Section 5.2. The URI reference may be relative or absolute. ResolveReference always returns a new [URL] instance, even if the returned URL is identical to either the base or reference. If ref is an absolute URL, then ResolveReference ignores base and returns a copy of ref.

Parameters

ref: URL

Returns URL

string

  • string(): string

String reassembles the [URL] into a valid URL string. The general form of the result is one of:

scheme:opaque?query#fragment scheme://userinfo@host/path?query#fragmentCopy

If u.Opaque is non-empty, String uses the first form; otherwise it uses the second form. Any non-ASCII characters in host are escaped. To obtain the path, String uses u.EscapedPath().

In the second form, the following rules apply:

- if u.Scheme is empty, scheme: is omitted. - if u.User is nil, userinfo@ is omitted. - if u.Host is empty, host/ is omitted. - if u.Scheme and u.Host are empty and u.User is nil, the entire scheme://userinfo@host/ is omitted. - if u.Host is non-empty and u.Path begins with a /, the form host/path does not add its own /. - if u.RawQuery is empty, ?query is omitted. - if u.Fragment is empty, #fragment is omitted.Copy

Returns string

unmarshalBinary

  • unmarshalBinary(text): void

Parameters

text: string | number[]

Returns void

Properties

forceQuery

forceQuery: boolean

fragment

fragment: string

host

host: string

omitHost

omitHost: boolean

opaque

opaque: string

path

path: string

rawFragment

rawFragment: string

rawPath

rawPath: string

rawQuery

rawQuery: string

scheme

scheme: string

Optional user

user?: Userinfo

Settings

Member Visibility

  • Inherited

Theme

OSLightDark

On This Page

Generated using TypeDoc