gi-glib-2.0.30: GLib bindings

Copyright | Will Thompson and Iñaki García Etxebarria
License | LGPL-2.1
Maintainer | Iñaki García Etxebarria
Safe Haskell | None
Language | Haskell2010

GI.GLib.Structs.Uri

Contents

- Exported types
- Methods
  - build
  - buildWithUser
  - errorQuark
  - escapeBytes
  - escapeString
  - getAuthParams
  - getFlags
  - getFragment
  - getHost
  - getPassword
  - getPath
  - getPort
  - getQuery
  - getScheme
  - getUser
  - getUserinfo
  - isValid
  - join
  - joinWithUser
  - listExtractUris
  - parse
  - parseParams
  - parseRelative
  - parseScheme
  - peekScheme
  - resolveRelative
  - split
  - splitNetwork
  - splitWithUser
  - toString
  - toStringPartial
  - unescapeBytes
  - unescapeSegment
  - unescapeString

Description

The `GUri` type and related functions can be used to parse URIs into their components, and build valid URIs from individual components.

Since `GUri` only represents absolute URIs, all `GUri`s will have a URI scheme, so `uriGetScheme` will always return a non-`NULL` answer. Likewise, by definition, all URIs have a path component, so `uriGetPath` will always return a non-`NULL` string (which may be empty).

If the URI string has an ‘authority’ component (that is, if the scheme is followed by `://` rather than just `:`), then the `GUri` will contain a hostname, and possibly a port and ‘userinfo’. Additionally, depending on how the `GUri` was constructed/parsed (for example, using the `G_URI_FLAGS_HAS_PASSWORD` and `G_URI_FLAGS_HAS_AUTH_PARAMS` flags), the userinfo may be split out into a username, password, and additional authorization-related parameters.

Normally, the components of a `GUri` will have all `%`-encoded characters decoded. However, if you construct/parse a `GUri` with `G_URI_FLAGS_ENCODED`, then the `%`-encoding will be preserved instead in the userinfo, path, and query fields (and in the host field if also created with `G_URI_FLAGS_NON_DNS`). In particular, this is necessary if the URI may contain binary data or non-UTF-8 text, or if decoding the components might change the interpretation of the URI.

For example, with the encoded flag:

### c code

    g_autoptr(GUri) uri = g_uri_parse ("http://host/path?query=http%3A%2F%2Fhost%2Fpath%3Fparam%3Dvalue", G_URI_FLAGS_ENCODED, &err);
    g_assert_cmpstr (g_uri_get_query (uri), ==, "query=http%3A%2F%2Fhost%2Fpath%3Fparam%3Dvalue");

While the default `%`-decoding behaviour would give:

### c code

    g_autoptr(GUri) uri = g_uri_parse ("http://host/path?query=http%3A%2F%2Fhost%2Fpath%3Fparam%3Dvalue", G_URI_FLAGS_NONE, &err);
    g_assert_cmpstr (g_uri_get_query (uri), ==, "query=http://host/path?param=value");

During decoding, if an invalid UTF-8 string is encountered, parsing will fail with an error indicating the bad string location:

### c code

    g_autoptr(GUri) uri = g_uri_parse ("http://host/path?query=http%3A%2F%2Fhost%2Fpath%3Fbad%3D%00alue", G_URI_FLAGS_NONE, &err);
    g_assert_error (err, G_URI_ERROR, G_URI_ERROR_BAD_QUERY);

You should pass `G_URI_FLAGS_ENCODED` or `G_URI_FLAGS_ENCODED_QUERY` if you need to handle that case manually. In particular, if the query string contains `=` characters that are `%`-encoded, you should let `uriParseParams` do the decoding once of the query.

`GUri` is immutable once constructed, and can safely be accessed from multiple threads. Its reference counting is atomic.

Note that the scope of `GUri` is to help manipulate URIs in various applications, following RFC 3986. In particular, it doesn't intend to cover web browser needs, and doesn’t implement the WHATWG URL standard. No APIs are provided to help prevent homograph attacks, so `GUri` is not suitable for formatting URIs for display to the user for making security-sensitive decisions.

## Relative and absolute URIs

As defined in RFC 3986, the hierarchical nature of URIs means that they can either be ‘relative references’ (sometimes referred to as ‘relative URIs’) or ‘URIs’ (for clarity, ‘URIs’ are referred to in this documentation as ‘absolute URIs’ — although in contrast to RFC 3986, fragment identifiers are always allowed).

Relative references have one or more components of the URI missing. In particular, they have no scheme. Any other component, such as hostname, query, etc. may be missing, apart from a path, which has to be specified (but may be empty). The path may be relative, starting with `./` rather than `/`.

For example, a valid relative reference is `./path?query`, `/?query#fragment` or `//example.com`.

Absolute URIs have a scheme specified. Any other components of the URI which are missing are specified as explicitly unset in the URI, rather than being resolved relative to a base URI using `uriParseRelative`.

For example, a valid absolute URI is `file:///home/bob` or `https://search.com?query=string`.

A `GUri` instance is always an absolute URI. A string may be an absolute URI or a relative reference; see the documentation for individual functions as to what forms they accept.

## Parsing URIs

The most minimalist APIs for parsing URIs are `uriSplit` and `uriSplitWithUser`. These split a URI into its component parts, and return the parts; the difference between the two is that `uriSplit` treats the ‘userinfo’ component of the URI as a single element, while `uriSplitWithUser` can (depending on the [flags`gLib`.UriFlags] you pass) treat it as containing a username, password, and authentication parameters. Alternatively, `uriSplitNetwork` can be used when you are only interested in the components that are needed to initiate a network connection to the service (scheme, host, and port).

`uriParse` is similar to `uriSplit`, but instead of returning individual strings, it returns a `GUri` structure (and it requires that the URI be an absolute URI).

`uriResolveRelative` and `uriParseRelative` allow you to resolve a relative URI relative to a base URI. `uriResolveRelative` takes two strings and returns a string, and `uriParseRelative` takes a `GUri` and a string and returns a `GUri`.

All of the parsing functions take a [flags`gLib`.UriFlags] argument describing exactly how to parse the URI; see the documentation for that type for more details on the specific flags that you can pass. If you need to choose different flags based on the type of URI, you can use `uriPeekScheme` on the URI string to check the scheme first, and use that to decide what flags to parse it with.

For example, you might want to use `G_URI_PARAMS_WWW_FORM` when parsing the params for a web URI, so compare the result of `uriPeekScheme` against `http` and `https`.

## Building URIs

`uriJoin` and `uriJoinWithUser` can be used to construct valid URI strings from a set of component strings. They are the inverse of `uriSplit` and `uriSplitWithUser`.

Similarly, `uriBuild` and `uriBuildWithUser` can be used to construct a `GUri` from a set of component strings.

As with the parsing functions, the building functions take a [flags`gLib`.UriFlags] argument. In particular, it is important to keep in mind whether the URI components you are using are already `%`-encoded. If so, you must pass the `G_URI_FLAGS_ENCODED` flag.

## `file://` URIs

Note that Windows and Unix both define special rules for parsing `file://` URIs (involving non-UTF-8 character sets on Unix, and the interpretation of path separators on Windows). `GUri` does not implement these rules. Use `filenameFromUri` and `filenameToUri` if you want to properly convert between `file://` URIs and local filenames.

## URI Equality

Note that there is no `g_uri_equal ()` function, because comparing URIs usefully requires scheme-specific knowledge that `GUri` does not have. `GUri` can help with normalization if you use the various encoded [flags`gLib`.UriFlags] as well as `G_URI_FLAGS_SCHEME_NORMALIZE` however it is not comprehensive. For example, `data:,foo` and `data:;base64,Zm9v` resolve to the same thing according to the `data:` URI specification which GLib does not handle.

Since: 2.66

Synopsis

- newtype Uri = Uri (ManagedPtr Uri)
- uriBuild :: (HasCallStack, MonadIO m) => [UriFlags] -> Text -> Maybe Text -> Maybe Text -> Int32 -> Text -> Maybe Text -> Maybe Text -> m Uri
- uriBuildWithUser :: (HasCallStack, MonadIO m) => [UriFlags] -> Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Int32 -> Text -> Maybe Text -> Maybe Text -> m Uri
- uriErrorQuark :: (HasCallStack, MonadIO m) => m Word32
- uriEscapeBytes :: (HasCallStack, MonadIO m) => ByteString -> Maybe Text -> m Text
- uriEscapeString :: (HasCallStack, MonadIO m) => Text -> Maybe Text -> Bool -> m Text
- uriGetAuthParams :: (HasCallStack, MonadIO m) => Uri -> m (Maybe Text)
- uriGetFlags :: (HasCallStack, MonadIO m) => Uri -> m [UriFlags]
- uriGetFragment :: (HasCallStack, MonadIO m) => Uri -> m (Maybe Text)
- uriGetHost :: (HasCallStack, MonadIO m) => Uri -> m (Maybe Text)
- uriGetPassword :: (HasCallStack, MonadIO m) => Uri -> m (Maybe Text)
- uriGetPath :: (HasCallStack, MonadIO m) => Uri -> m Text
- uriGetPort :: (HasCallStack, MonadIO m) => Uri -> m Int32
- uriGetQuery :: (HasCallStack, MonadIO m) => Uri -> m (Maybe Text)
- uriGetScheme :: (HasCallStack, MonadIO m) => Uri -> m Text
- uriGetUser :: (HasCallStack, MonadIO m) => Uri -> m (Maybe Text)
- uriGetUserinfo :: (HasCallStack, MonadIO m) => Uri -> m (Maybe Text)
- uriIsValid :: (HasCallStack, MonadIO m) => Text -> [UriFlags] -> m ()
- uriJoin :: (HasCallStack, MonadIO m) => [UriFlags] -> Maybe Text -> Maybe Text -> Maybe Text -> Int32 -> Text -> Maybe Text -> Maybe Text -> m Text
- uriJoinWithUser :: (HasCallStack, MonadIO m) => [UriFlags] -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Maybe Text -> Int32 -> Text -> Maybe Text -> Maybe Text -> m Text
- uriListExtractUris :: (HasCallStack, MonadIO m) => Text -> m [Text]
- uriParse :: (HasCallStack, MonadIO m) => Text -> [UriFlags] -> m Uri
- uriParseParams :: (HasCallStack, MonadIO m) => Text -> Int64 -> Text -> [UriParamsFlags] -> m (Map Text Text)
- uriParseRelative :: (HasCallStack, MonadIO m) => Maybe Uri -> Text -> [UriFlags] -> m Uri
- uriParseScheme :: (HasCallStack, MonadIO m) => Text -> m (Maybe Text)
- uriPeekScheme :: (HasCallStack, MonadIO m) => Text -> m (Maybe Text)
- uriResolveRelative :: (HasCallStack, MonadIO m) => Maybe Text -> Text -> [UriFlags] -> m Text
- uriSplit :: (HasCallStack, MonadIO m) => Text -> [UriFlags] -> m (Maybe Text, Maybe Text, Maybe Text, Int32, Text, Maybe Text, Maybe Text)
- uriSplitNetwork :: (HasCallStack, MonadIO m) => Text -> [UriFlags] -> m (Maybe Text, Maybe Text, Int32)
- uriSplitWithUser :: (HasCallStack, MonadIO m) => Text -> [UriFlags] -> m (Maybe Text, Maybe Text, Maybe Text, Maybe Text, Maybe Text, Int32, Text, Maybe Text, Maybe Text)
- uriToString :: (HasCallStack, MonadIO m) => Uri -> m Text
- uriToStringPartial :: (HasCallStack, MonadIO m) => Uri -> [UriHideFlags] -> m Text
- uriUnescapeBytes :: (HasCallStack, MonadIO m) => Text -> Int64 -> Maybe Text -> m Bytes
- uriUnescapeSegment :: (HasCallStack, MonadIO m) => Maybe Text -> Maybe Text -> Maybe Text -> m (Maybe Text)
- uriUnescapeString :: (HasCallStack, MonadIO m) => Text -> Maybe Text -> m (Maybe Text)

# Exported types

newtype Uri Source #

Memory-managed wrapper type.

Constructors

Uri (ManagedPtr Uri) |

#### Instances

Instances details

Eq Uri Source # |
Instance details Defined in GI.GLib.Structs.Uri Methods (==) :: Uri -> Uri -> Bool Source # (/=) :: Uri -> Uri -> Bool Source #
GBoxed Uri Source # |
Instance details Defined in GI.GLib.Structs.Uri
ManagedPtrNewtype Uri Source # |
Instance details Defined in GI.GLib.Structs.Uri Methods toManagedPtr :: Uri -> ManagedPtr Uri Source #
TypedObject Uri Source # |
Instance details Defined in GI.GLib.Structs.Uri Methods glibType :: IO GType Source #
HasParentTypes Uri Source # |
Instance details Defined in GI.GLib.Structs.Uri
IsGValue (Maybe Uri) Source # | Convert `Uri` to and from `GValue`. See `toGValue` and `fromGValue`.
Instance details Defined in GI.GLib.Structs.Uri Methods gvalueGType_ :: IO GType Source # gvalueSet_ :: Ptr GValue -> Maybe Uri -> IO () Source # gvalueGet_ :: Ptr GValue -> IO (Maybe Uri) Source #
type ParentTypes Uri Source # |
Instance details Defined in GI.GLib.Structs.Uri type ParentTypes Uri = '[] :: [Type]

# Methods

### Click to display all available methods, including inherited ones

Expand

#### Methods

parseRelative, toString, toStringPartial.

#### Getters

getAuthParams, getFlags, getFragment, getHost, getPassword, getPath, getPort, getQuery, getScheme, getUser, getUserinfo.

#### Setters

None.

## build

uriBuild Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> [UriFlags] | `flags`: flags describing how to build the `Uri`
-> Text | `scheme`: the URI scheme
-> Maybe Text | `userinfo`: the userinfo component, or `Nothing`
-> Maybe Text | `host`: the host component, or `Nothing`
-> Int32 | `port`: the port, or `-1`
-> Text | `path`: the path component
-> Maybe Text | `query`: the query component, or `Nothing`
-> Maybe Text | `fragment`: the fragment, or `Nothing`
-> m Uri | Returns: a new `Uri`

Creates a new `Uri` from the given components according to `flags`.

See also `uriBuildWithUser`, which allows specifying the components of the "userinfo" separately.

Since: 2.66

## buildWithUser

uriBuildWithUser Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> [UriFlags] | `flags`: flags describing how to build the `Uri`
-> Text | `scheme`: the URI scheme
-> Maybe Text | `user`: the user component of the userinfo, or `Nothing`
-> Maybe Text | `password`: the password component of the userinfo, or `Nothing`
-> Maybe Text | `authParams`: the auth params of the userinfo, or `Nothing`
-> Maybe Text | `host`: the host component, or `Nothing`
-> Int32 | `port`: the port, or `-1`
-> Text | `path`: the path component
-> Maybe Text | `query`: the query component, or `Nothing`
-> Maybe Text | `fragment`: the fragment, or `Nothing`
-> m Uri | Returns: a new `Uri`

Creates a new `Uri` from the given components according to `flags` (`UriFlagsHasPassword` is added unconditionally). The `flags` must be coherent with the passed values, in particular use `%`-encoded values with `UriFlagsEncoded`.

In contrast to `uriBuild`, this allows specifying the components of the ‘userinfo’ field separately. Note that `user` must be non-`Nothing` if either `password` or `authParams` is non-`Nothing`.

Since: 2.66

## errorQuark

uriErrorQuark :: (HasCallStack, MonadIO m) => m Word32 Source #

No description available in the introspection data.

## escapeBytes

uriEscapeBytes Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> ByteString | `unescaped`: the unescaped input data.
-> Maybe Text | `reservedCharsAllowed`: a string of reserved characters that are allowed to be used, or `Nothing`.
-> m Text | Returns: an escaped version of `unescaped`. The returned string should be freed when no longer needed.

Escapes arbitrary data for use in a URI.

Normally all characters that are not ‘unreserved’ (i.e. ASCII alphanumerical characters plus dash, dot, underscore and tilde) are escaped. But if you specify characters in `reservedCharsAllowed` they are not escaped. This is useful for the ‘reserved’ characters in the URI specification, since those are allowed unescaped in some portions of a URI.

Though technically incorrect, this will also allow escaping nul bytes as `%``00`.

Since: 2.66

## escapeString

uriEscapeString Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `unescaped`: the unescaped input string.
-> Maybe Text | `reservedCharsAllowed`: a string of reserved characters that are allowed to be used, or `Nothing`.
-> Bool | `allowUtf8`: `True` if the result can include UTF-8 characters.
-> m Text | Returns: an escaped version of `unescaped`. The returned string should be freed when no longer needed.

Escapes a string for use in a URI.

Normally all characters that are not "unreserved" (i.e. ASCII alphanumerical characters plus dash, dot, underscore and tilde) are escaped. But if you specify characters in `reservedCharsAllowed` they are not escaped. This is useful for the "reserved" characters in the URI specification, since those are allowed unescaped in some portions of a URI.

Since: 2.16

## getAuthParams

uriGetAuthParams Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Uri | `uri`: a `Uri`
-> m (Maybe Text) | Returns: `uri`'s authentication parameters.

Gets `uri`'s authentication parameters, which may contain `%`-encoding, depending on the flags with which `uri` was created. (If `uri` was not created with `UriFlagsHasAuthParams` then this will be `Nothing`.)

Depending on the URI scheme, `uriParseParams` may be useful for further parsing this information.

Since: 2.66

## getFlags

uriGetFlags Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Uri | `uri`: a `Uri`
-> m [UriFlags] | Returns: `uri`'s flags.

Gets `uri`'s flags set upon construction.

Since: 2.66

## getFragment

uriGetFragment Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Uri | `uri`: a `Uri`
-> m (Maybe Text) | Returns: `uri`'s fragment.

Gets `uri`'s fragment, which may contain `%`-encoding, depending on the flags with which `uri` was created.

Since: 2.66

## getHost

uriGetHost Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Uri | `uri`: a `Uri`
-> m (Maybe Text) | Returns: `uri`'s host.

Gets `uri`'s host. This will never have `%`-encoded characters, unless it is non-UTF-8 (which can only be the case if `uri` was created with `UriFlagsNonDns`).

If `uri` contained an IPv6 address literal, this value will be just that address, without the brackets around it that are necessary in the string form of the URI. Note that in this case there may also be a scope ID attached to the address. Eg, `fe80::1234%``em1` (or `fe80::1234%``25em1` if the string is still encoded).

Since: 2.66

## getPassword

uriGetPassword Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Uri | `uri`: a `Uri`
-> m (Maybe Text) | Returns: `uri`'s password.

Gets `uri`'s password, which may contain `%`-encoding, depending on the flags with which `uri` was created. (If `uri` was not created with `UriFlagsHasPassword` then this will be `Nothing`.)

Since: 2.66

## getPath

uriGetPath Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Uri | `uri`: a `Uri`
-> m Text | Returns: `uri`'s path.

Gets `uri`'s path, which may contain `%`-encoding, depending on the flags with which `uri` was created.

Since: 2.66

## getPort

uriGetPort Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Uri | `uri`: a `Uri`
-> m Int32 | Returns: `uri`'s port, or `-1` if no port was specified.

Gets `uri`'s port.

Since: 2.66

## getQuery

uriGetQuery Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Uri | `uri`: a `Uri`
-> m (Maybe Text) | Returns: `uri`'s query.

Gets `uri`'s query, which may contain `%`-encoding, depending on the flags with which `uri` was created.

For queries consisting of a series of `name=value` parameters, `UriParamsIter` or `uriParseParams` may be useful.

Since: 2.66

## getScheme

uriGetScheme Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Uri | `uri`: a `Uri`
-> m Text | Returns: `uri`'s scheme.

Gets `uri`'s scheme. Note that this will always be all-lowercase, regardless of the string or strings that `uri` was created from.

Since: 2.66

## getUser

uriGetUser Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Uri | `uri`: a `Uri`
-> m (Maybe Text) | Returns: `uri`'s user.

Gets the ‘username’ component of `uri`'s userinfo, which may contain `%`-encoding, depending on the flags with which `uri` was created. If `uri` was not created with `UriFlagsHasPassword` or `UriFlagsHasAuthParams`, this is the same as `uriGetUserinfo`.

Since: 2.66

## getUserinfo

uriGetUserinfo Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Uri | `uri`: a `Uri`
-> m (Maybe Text) | Returns: `uri`'s userinfo.

Gets `uri`'s userinfo, which may contain `%`-encoding, depending on the flags with which `uri` was created.

Since: 2.66

## isValid

uriIsValid Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `uriString`: a string containing an absolute URI
-> [UriFlags] | `flags`: flags for parsing `uriString`
-> m () | (Can throw `GError`)

Parses `uriString` according to `flags`, to determine whether it is a valid absolute URI, i.e. it does not need to be resolved relative to another URI using `uriParseRelative`.

If it’s not a valid URI, an error is returned explaining how it’s invalid.

See `uriSplit`, and the definition of `UriFlags`, for more information on the effect of `flags`.

Since: 2.66

## join

uriJoin Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> [UriFlags] | `flags`: flags describing how to build the URI string
-> Maybe Text | `scheme`: the URI scheme, or `Nothing`
-> Maybe Text | `userinfo`: the userinfo component, or `Nothing`
-> Maybe Text | `host`: the host component, or `Nothing`
-> Int32 | `port`: the port, or `-1`
-> Text | `path`: the path component
-> Maybe Text | `query`: the query component, or `Nothing`
-> Maybe Text | `fragment`: the fragment, or `Nothing`
-> m Text | Returns: an absolute URI string

Joins the given components together according to `flags` to create an absolute URI string. `path` may not be `Nothing` (though it may be the empty string).

When `host` is present, `path` must either be empty or begin with a slash (`/`) character. When `host` is not present, `path` cannot begin with two slash characters (`//`). See RFC 3986, section 3.

See also `uriJoinWithUser`, which allows specifying the components of the ‘userinfo’ separately.

`UriFlagsHasPassword` and `UriFlagsHasAuthParams` are ignored if set in `flags`.

Since: 2.66

## joinWithUser

uriJoinWithUser Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> [UriFlags] | `flags`: flags describing how to build the URI string
-> Maybe Text | `scheme`: the URI scheme, or `Nothing`
-> Maybe Text | `user`: the user component of the userinfo, or `Nothing`
-> Maybe Text | `password`: the password component of the userinfo, or `Nothing`
-> Maybe Text | `authParams`: the auth params of the userinfo, or `Nothing`
-> Maybe Text | `host`: the host component, or `Nothing`
-> Int32 | `port`: the port, or `-1`
-> Text | `path`: the path component
-> Maybe Text | `query`: the query component, or `Nothing`
-> Maybe Text | `fragment`: the fragment, or `Nothing`
-> m Text | Returns: an absolute URI string

Joins the given components together according to `flags` to create an absolute URI string. `path` may not be `Nothing` (though it may be the empty string).

In contrast to `uriJoin`, this allows specifying the components of the ‘userinfo’ separately. It otherwise behaves the same.

`UriFlagsHasPassword` and `UriFlagsHasAuthParams` are ignored if set in `flags`.

Since: 2.66

## listExtractUris

uriListExtractUris Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `uriList`: an URI list
-> m [Text] | Returns: a newly allocated `Nothing`-terminated list of strings holding the individual URIs. The array should be freed with `strfreev`.

Splits an URI list conforming to the text/uri-list mime type defined in RFC 2483 into individual URIs, discarding any comments. The URIs are not validated.

Since: 2.6

## parse

uriParse Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `uriString`: a string representing an absolute URI
-> [UriFlags] | `flags`: flags describing how to parse `uriString`
-> m Uri | Returns: a new `Uri`, or NULL on error. (Can throw `GError`)

Parses `uriString` according to `flags`. If the result is not a valid absolute URI, it will be discarded, and an error returned.

Since: 2.66

## parseParams

uriParseParams Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `params`: a `%`-encoded string containing `attribute=value` parameters
-> Int64 | `length`: the length of `params`, or `-1` if it is nul-terminated
-> Text | `separators`: the separator byte character set between parameters. (usually `&`, but sometimes `;` or both `&;`). Note that this function works on bytes not characters, so it can't be used to delimit UTF-8 strings for anything but ASCII characters. You may pass an empty set, in which case no splitting will occur.
-> [UriParamsFlags] | `flags`: flags to modify the way the parameters are handled.
-> m (Map Text Text) | Returns: A hash table of attribute/value pairs, with both names and values fully-decoded; or `Nothing` on error. (Can throw `GError`)

Many URI schemes include one or more attribute/value pairs as part of the URI value. This method can be used to parse them into a hash table. When an attribute has multiple occurrences, the last value is the final returned value. If you need to handle repeated attributes differently, use `UriParamsIter`.

The `params` string is assumed to still be `%`-encoded, but the returned values will be fully decoded. (Thus it is possible that the returned values may contain `=` or `separators`, if the value was encoded in the input.) Invalid `%`-encoding is treated as with the `UriFlagsParseRelaxed` rules for `uriParse`. (However, if `params` is the path or query string from a `Uri` that was parsed without `UriFlagsParseRelaxed` and `UriFlagsEncoded`, then you already know that it does not contain any invalid encoding.)

`UriParamsFlagsWwwForm` is handled as documented for `uriParamsIterInit`.

If `UriParamsFlagsCaseInsensitive` is passed to `flags`, attributes will be compared case-insensitively, so a params string `attr=123&Attr=456` will only return a single attribute–value pair, `Attr=456`. Case will be preserved in the returned attributes.

If `params` cannot be parsed (for example, it contains two `separators` characters in a row), then `error` is set and `Nothing` is returned.

Since: 2.66

## parseRelative

uriParseRelative Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Maybe Uri | `baseUri`: a base absolute URI
-> Text | `uriRef`: a string representing a relative or absolute URI
-> [UriFlags] | `flags`: flags describing how to parse `uriRef`
-> m Uri | Returns: a new `Uri`, or NULL on error. (Can throw `GError`)

Parses `uriRef` according to `flags` and, if it is a relative URI, resolves it relative to `baseUri`. If the result is not a valid absolute URI, it will be discarded, and an error returned.

Since: 2.66

## parseScheme

uriParseScheme Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `uri`: a valid URI.
-> m (Maybe Text) | Returns: The ‘scheme’ component of the URI, or `Nothing` on error. The returned string should be freed when no longer needed.

Gets the scheme portion of a URI string. RFC 3986 decodes the scheme as:

    URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

Common schemes include `file`, `https`, `svn+ssh`, etc.

Since: 2.16

## peekScheme

uriPeekScheme Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `uri`: a valid URI.
-> m (Maybe Text) | Returns: The ‘scheme’ component of the URI, or `Nothing` on error. The returned string is normalized to all-lowercase, and interned via `internString`, so it does not need to be freed.

Gets the scheme portion of a URI string. RFC 3986 decodes the scheme as:

    URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]

Common schemes include `file`, `https`, `svn+ssh`, etc.

Unlike `uriParseScheme`, the returned scheme is normalized to all-lowercase and does not need to be freed.

Since: 2.66

## resolveRelative

uriResolveRelative Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Maybe Text | `baseUriString`: a string representing a base URI
-> Text | `uriRef`: a string representing a relative or absolute URI
-> [UriFlags] | `flags`: flags describing how to parse `uriRef`
-> m Text | Returns: the resolved URI string, or NULL on error. (Can throw `GError`)

Parses `uriRef` according to `flags` and, if it is a relative URI, resolves it relative to `baseUriString`. If the result is not a valid absolute URI, it will be discarded, and an error returned.

(If `baseUriString` is `Nothing`, this just returns `uriRef`, or `Nothing` if `uriRef` is invalid or not absolute.)

Since: 2.66

## split

uriSplit Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `uriRef`: a string containing a relative or absolute URI
-> [UriFlags] | `flags`: flags for parsing `uriRef`
-> m (Maybe Text, Maybe Text, Maybe Text, Int32, Text, Maybe Text, Maybe Text) | (Can throw `GError`)

Parses `uriRef` (which can be an absolute or relative URI) according to `flags`, and returns the pieces. Any component that doesn't appear in `uriRef` will be returned as `Nothing` (but note that all URIs always have a path component, though it may be the empty string).

If `flags` contains `UriFlagsEncoded`, then `%`-encoded characters in `uriRef` will remain encoded in the output strings. (If not, then all such characters will be decoded.) Note that decoding will only work if the URI components are ASCII or UTF-8, so you will need to use `UriFlagsEncoded` if they are not.

Note that the `UriFlagsHasPassword` and `UriFlagsHasAuthParams` `flags` are ignored by `uriSplit`, since it always returns only the full userinfo; use `uriSplitWithUser` if you want it split up.

Since: 2.66

## splitNetwork

uriSplitNetwork Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `uriString`: a string containing an absolute URI
-> [UriFlags] | `flags`: flags for parsing `uriString`
-> m (Maybe Text, Maybe Text, Int32) | (Can throw `GError`)

Parses `uriString` (which must be an absolute URI) according to `flags`, and returns the pieces relevant to connecting to a host. See the documentation for `uriSplit` for more details; this is mostly a wrapper around that function with simpler arguments. However, it will return an error if `uriString` is a relative URI, or does not contain a hostname component.

Since: 2.66

## splitWithUser

uriSplitWithUser Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `uriRef`: a string containing a relative or absolute URI
-> [UriFlags] | `flags`: flags for parsing `uriRef`
-> m (Maybe Text, Maybe Text, Maybe Text, Maybe Text, Maybe Text, Int32, Text, Maybe Text, Maybe Text) | (Can throw `GError`)

Parses `uriRef` (which can be an absolute or relative URI) according to `flags`, and returns the pieces. Any component that doesn't appear in `uriRef` will be returned as `Nothing` (but note that all URIs always have a path component, though it may be the empty string).

See `uriSplit`, and the definition of `UriFlags`, for more information on the effect of `flags`. Note that `password` will only be parsed out if `flags` contains `UriFlagsHasPassword`, and `authParams` will only be parsed out if `flags` contains `UriFlagsHasAuthParams`.

Since: 2.66

## toString

uriToString Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Uri | `uri`: a `Uri`
-> m Text | Returns: a string representing `uri`, which the caller must free.

Returns a string representing `uri`.

This is not guaranteed to return a string which is identical to the string that `uri` was parsed from. However, if the source URI was syntactically correct (according to RFC 3986), and it was parsed with `UriFlagsEncoded`, then `uriToString` is guaranteed to return a string which is at least semantically equivalent to the source URI (according to RFC 3986).

If `uri` might contain sensitive details, such as authentication parameters, or private data in its query string, and the returned string is going to be logged, then consider using `uriToStringPartial` to redact parts.

Since: 2.66

## toStringPartial

uriToStringPartial Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Uri | `uri`: a `Uri`
-> [UriHideFlags] | `flags`: flags describing what parts of `uri` to hide
-> m Text | Returns: a string representing `uri`, which the caller must free.

Returns a string representing `uri`, subject to the options in `flags`. See `uriToString` and `UriHideFlags` for more details.

Since: 2.66

## unescapeBytes

uriUnescapeBytes Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `escapedString`: A URI-escaped string
-> Int64 | `length`: the length (in bytes) of `escapedString` to escape, or `-1` if it is nul-terminated.
-> Maybe Text | `illegalCharacters`: a string of illegal characters not to be allowed, or `Nothing`.
-> m Bytes | Returns: an unescaped version of `escapedString` or `Nothing` on error (if decoding failed, using `UriErrorFailed` error code). The returned `Bytes` should be unreffed when no longer needed. (Can throw `GError`)

Unescapes a segment of an escaped string as binary data.

Note that in contrast to `uriUnescapeString`, this does allow nul bytes to appear in the output.

If any of the characters in `illegalCharacters` appears as an escaped character in `escapedString`, then that is an error and `Nothing` will be returned. This is useful if you want to avoid for instance having a slash being expanded in an escaped path element, which might confuse pathname handling.

Since: 2.66

## unescapeSegment

uriUnescapeSegment Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Maybe Text | `escapedString`: A string, may be `Nothing`
-> Maybe Text | `escapedStringEnd`: Pointer to end of `escapedString`, may be `Nothing`
-> Maybe Text | `illegalCharacters`: An optional string of illegal characters not to be allowed, may be `Nothing`
-> m (Maybe Text) | Returns: an unescaped version of `escapedString`, or `Nothing` on error. The returned string should be freed when no longer needed. As a special case if `Nothing` is given for `escapedString`, this function will return `Nothing`.

Unescapes a segment of an escaped string.

If any of the characters in `illegalCharacters` or the NUL character appears as an escaped character in `escapedString`, then that is an error and `Nothing` will be returned. This is useful if you want to avoid for instance having a slash being expanded in an escaped path element, which might confuse pathname handling.

Note: `NUL` byte is not accepted in the output, in contrast to `uriUnescapeBytes`.

Since: 2.16

## unescapeString

uriUnescapeString Source #

Arguments

:: (HasCallStack, MonadIO m) |
=> Text | `escapedString`: an escaped string to be unescaped.
-> Maybe Text | `illegalCharacters`: a string of illegal characters not to be allowed, or `Nothing`.
-> m (Maybe Text) | Returns: an unescaped version of `escapedString`. The returned string should be freed when no longer needed.

Unescapes a whole escaped string.

If any of the characters in `illegalCharacters` or the NUL character appears as an escaped character in `escapedString`, then that is an error and `Nothing` will be returned. This is useful if you want to avoid for instance having a slash being expanded in an escaped path element, which might confuse pathname handling.

Since: 2.16