Class representing a URI.

Synopsis

Declared in <folly/Uri.h>

class Uri;

Description

Consider http://www.facebook.com/foo/bar?key=foo#anchor

The URI is broken down into its parts: scheme ("http"), authority (ie. host and port, in most cases: "www.facebook.com"), path ("/foo/bar"), query ("key=foo") and fragment ("anchor"). The scheme is lower‐cased.

If this Uri represents a URL, note that, to prevent ambiguity, the component parts are NOT percent‐decoded; you should do this yourself with uriUnescape() (for the authority and path) and uriUnescape(..., UriEscapeMode::QUERY) (for the query, but probably only after splitting at '&' to identify the individual parameters).

Member Functions

Name

Description

Uri [constructor]

Parse a Uri from a string. Same as tryFromString except it throws a std::invalid_argument if there's an error.

authority

Return the authority component (user info, host and port) of the URI.

fbstr

Reassemble the URI into an fbstring.

fragment

Return the fragment component of the URI.

getQueryParams

Get query parameters as key‐value pairs. e.g. for URI containing query string: key1=foo&key2=&key3&=bar&=bar= In returned list, there are 3 entries: "key1" => "foo" "key2" => "" "key3" => "" Parts "=bar" and "=bar=" are ignored, as they are not valid query parameters. "=bar" is missing parameter name, while "=bar=" has more than one equal signs, we don't know which one is the delimiter for key and value.

host

Get host part of URI. If host is an IPv6 address, square brackets will be returned, for example: "[::1]".

hostname

Get host part of URI. If host is an IPv6 address, square brackets will not be returned, for example "::1"; otherwise it returns the same thing as host().

password

Return the password component of the authority.

path

Return the path component of the URI.

port

Return the port component of the URI.

query

Return the query component of the URI.

scheme

Return the scheme component, lower‐cased.

setPort

Set the port component and mark the URI as having an authority.

str

Reassemble the URI into a std::string.

toString

Reassemble the URI into a string of the given string type.

username

Return the username component of the authority.

Static Member Functions

Name

Description

tryFromString

Parse a Uri from a string.

Created with MrDocs