Module uri

This module implements URI parsing as specified by RFC 3986.

Types

Url = distinct string
  Source Edit
Uri = object
  scheme*, username*, password*: string
  hostname*, port*, path*, query*, anchor*: string
  opaque*: bool
  Source Edit

Procs

proc `$`(url: Url): string {.
deprecated, raises: [], tags: []
.}
Deprecated since 0.9.6: Use Uri instead.   Source Edit
proc `/`(a, b: Url): Url {.
deprecated, raises: [], tags: []
.}

Joins two URLs together, separating them with / if needed.

Deprecated since 0.9.6: Use Uri instead.

  Source Edit
proc add(url: var Url; a: Url) {.
deprecated, raises: [], tags: []
.}

Appends url to url.

Deprecated since 0.9.6: Use Uri instead.

  Source Edit
proc encodeUrl(s: string): string {.
raises: [], tags: []
.}
Encodes a value to be HTTP safe: This means that characters in the set {'A'..'Z', 'a'..'z', '0'..'9', '_'} are carried over to the result, a space is converted to '+' and every other character is encoded as '%xx' where xx denotes its hexadecimal value.   Source Edit
proc decodeUrl(s: string): string {.
raises: [], tags: []
.}
Decodes a value from its HTTP representation: This means that a '+' is converted to a space, '%xx' (where xx denotes a hexadecimal value) is converted to the character with ordinal number xx, and and every other character is carried over.   Source Edit
proc initUri(): Uri {.
raises: [], tags: []
.}
Initializes a URI.   Source Edit
proc parseUri(uri: string; result: var Uri) {.
raises: [], tags: []
.}
Parses a URI. The result variable will be cleared before.   Source Edit
proc parseUri(uri: string): Uri {.
raises: [], tags: []
.}
Parses a URI and returns it.   Source Edit
proc combine(base: Uri; reference: Uri): Uri {.
raises: [], tags: []
.}

Combines a base URI with a reference URI.

This uses the algorithm specified in section 5.2.2 of RFC 3986.

This means that the slashes inside the base URI's path as well as reference URI's path affect the resulting URI.

For building URIs you may wish to use `/` instead.

Examples:

let foo = combine(parseUri("http://example.com/foo/bar"), parseUri("/baz"))
assert foo.path == "/baz"

let bar = combine(parseUri("http://example.com/foo/bar"), parseUri("baz"))
assert bar.path == "/foo/baz"

let bar = combine(parseUri("http://example.com/foo/bar/"), parseUri("baz"))
assert bar.path == "/foo/bar/baz"
  Source Edit
proc combine(uris: varargs[Uri]): Uri {.
raises: [], tags: []
.}
Combines multiple URIs together.   Source Edit
proc isAbsolute(uri: Uri): bool {.
raises: [], tags: []
.}
returns true if URI is absolute, false otherwise   Source Edit
proc `/`(x: Uri; path: string): Uri {.
raises: [], tags: []
.}

Concatenates the path specified to the specified URI's path.

Contrary to the combine procedure you do not have to worry about the slashes at the beginning and end of the path and URI's path respectively.

Examples:

let foo = parseUri("http://example.com/foo/bar") / "/baz"
assert foo.path == "/foo/bar/baz"

let bar = parseUri("http://example.com/foo/bar") / "baz"
assert bar.path == "/foo/bar/baz"

let bar = parseUri("http://example.com/foo/bar/") / "baz"
assert bar.path == "/foo/bar/baz"
  Source Edit
proc `$`(u: Uri): string {.
raises: [], tags: []
.}
Returns the string representation of the specified URI object.   Source Edit