Url

class Url(source)

A canonical http or https URL. parse accepts text and rewrites it exactly as OkHttp 5.5.0's HttpUrl does when the host is ASCII: it percent-encodes with HttpUrl's sets (non-ASCII path and query text as UTF-8 in upper-case hex), resolves . and .. (the %2e forms included), drops the default port, gives an empty path /, trims TAB, LF, FF, CR and SP at the ends, drops a #fragment, keeps an existing %XX and a malformed % as typed, keeps a bare ? as an empty query, prints IPv6 in RFC 5952 form and an IPv4-mapped address as dotted IPv4, and keeps digits-and-dots hosts and a trailing dot as written. It is only ever stricter than HttpUrl: it refuses a backslash, whitespace or a control character anywhere in the text, an unpaired surrogate, any scheme but http and https and any separator but ://, user-info, a host that is non-ASCII, percent-encoded, outside a-z 0-9 - _ ., outside the length rules or holding an xn-- label, a malformed IPv6 literal (a zone included), and a port that is signed, non-numeric, 0 or above 65535. Building a URL from parts is done as text, then parsed; there is no builder.

Stable Core. Equality and hash are on the canonical text, so %2f and %2F, 127.1 and 127.0.0.1, h and h. are different URLs. toString is the full canonical URL, query included; use redacted for logs and messages.

Types

Link copied to clipboard
object Companion

The parser.

Properties

Link copied to clipboard

The canonical path, / at least; dot segments resolved, HttpUrl's path encode set applied.

Link copied to clipboard

The canonical query without its ?: "" for a bare ?, null when there is none. Not split into pairs; + stays +.

Link copied to clipboard

The canonical host: lower-case ASCII text, or an IPv6 literal without brackets (':' in host).

Link copied to clipboard
val port: Int

The effective port, 1..65535: the written port, or the scheme's default.

Link copied to clipboard

The scheme, http or https.

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean

Two Urls are equal when their canonical text, query included, is equal. See the class description for what makes two texts different.

Link copied to clipboard
open override fun hashCode(): Int

Returns a hash code consistent with equals: it is computed from the same properties.

Link copied to clipboard

Returns the URL for logs and messages: the query, which may carry credentials, is replaced.

Link copied to clipboard
open override fun toString(): String

The full canonical URL, query included; use redacted for logs and messages.