Uri

Implements an RFC 2396 compliant URI specification. See <A HREF="http://ftp.ics.uci.edu/pub/ietf/uri/rfc2396.txt">this page</A> for more information.

The implementation fails the spec on two counts: it doesn't insist on a scheme being present in the Uri, and it doesn't implement the "Relative References" support noted in section 5.2. The latter can be found in ocean.util.PathUtil instead.

Note that IRI support can be implied by assuming each of userinfo, path, query, and fragment are UTF-8 encoded (see <A HREF="http://www.w3.org/2001/Talks/0912-IUC-IRI/paper.html"> this page</A> for further details).

Constructors

this
this(uint initial_buffer_size)

Create an empty Uri

this
this(cstring uri)

Construct a Uri from the provided character string

this
this(cstring scheme, cstring host, cstring path, cstring query)

Construct a Uri from the given components. The query is optional.

this
this(UriView other)

Clone another Uri. This can be used to make a mutable Uri from an immutable UriView.

Members

Aliases

getDefaultPort
alias getDefaultPort = defaultPort
Undocumented in source.
getFragment
alias getFragment = fragment
Undocumented in source.
getHost
alias getHost = host
Undocumented in source.
getPath
alias getPath = path
Undocumented in source.
getPort
alias getPort = port

old method names

getQuery
alias getQuery = query
Undocumented in source.
getUserInfo
alias getUserInfo = userinfo
Undocumented in source.
getValidPort
alias getValidPort = validPort
Undocumented in source.
setFragment
alias setFragment = fragment
Undocumented in source.
setHost
alias setHost = host
Undocumented in source.
setPath
alias setPath = path
Undocumented in source.
setPort
alias setPort = port
Undocumented in source.
setQuery
alias setQuery = query
Undocumented in source.
setUserInfo
alias setUserInfo = userinfo
Undocumented in source.

Enums

ExcScheme
anonymousenum ExcScheme
Undocumented in source.
InvalidPort
anonymousenum InvalidPort
Undocumented in source.

Functions

decode
mstring decode(cstring s)

Decode a duplicated string with potential %hex values in it

defaultPort
int defaultPort(cstring scheme)

Return the default port for the given scheme. InvalidPort is returned if the scheme is unknown, or does not accept a port.

extendQuery
cstring extendQuery(cstring tail)

Extend the Uri query

fragment
cstring fragment()

Return the parsed fragment, or null if a fragment was not provided.

fragment
Uri fragment(cstring fragment)

Set the Uri fragment

getNormalizedScheme
cstring getNormalizedScheme(mstring buffer)

Return the parsed scheme, or null if the scheme was not specified. Automatically normalizes scheme (converts to lower case)

host
cstring host()

Return the parsed host, or null if the host was not specified

host
Uri host(cstring host)

Set the Uri host

isGeneric
bool isGeneric()

Return whether or not the Uri scheme is considered generic.

parse
Uri parse(cstring uri, bool relative)

Parsing is performed according to RFC 2396

path
cstring path()

Return the parsed path, or null if the path was not provided.

path
Uri path(cstring path)

Set the Uri path

port
int port()

Return the parsed port number, or InvalidPort if the port was not provided.

port
Uri port(int port)

Set the Uri port

produce
size_t produce(Consumer consume)
size_t produce(Buffer!(char) buffer)

Emit the content of this Uri via the provided Consumer. The output is constructed per RFC 2396.

query
cstring query()

Return the parsed query, or null if a query was not provided.

query
Uri query(char[] query)

Set the Uri query

relParse
Uri relParse(mstring uri)

Parse the given uri, with support for relative URLs

reset
void reset()

Clear everything to null.

scheme
cstring scheme()

Return the parsed scheme, or null if the scheme was not specified

scheme
Uri scheme(cstring scheme)

Set the Uri scheme

toString
istring toString()

Emit the content of this Uri via the provided Consumer. The output is constructed per RFC 2396.

userinfo
cstring userinfo()

Return the parsed userinfo, or null if userinfo was not provided.

userinfo
Uri userinfo(cstring userinfo)

Set the Uri userinfo

validPort
int validPort()

Return a valid port number by performing a lookup on the known schemes if the port was not explicitly specified.

Static functions

encode
size_t encode(Consumer consume, cstring s, int flags)

Encode uri characters into a Consumer, such that reserved chars are converted into their %hex version.

encode
mstring encode(cstring text, int flags)

Encode uri characters into a string, such that reserved chars are converted into their %hex version.

Inherited Members

From UriView

getPort
alias getPort = port
Undocumented in source.
getDefaultPort
alias getDefaultPort = defaultPort
Undocumented in source.
getHost
alias getHost = host
Undocumented in source.
getValidPort
alias getValidPort = validPort
Undocumented in source.
getUserInfo
alias getUserInfo = userinfo
Undocumented in source.
getPath
alias getPath = path
Undocumented in source.
getQuery
alias getQuery = query
Undocumented in source.
getFragment
alias getFragment = fragment
Undocumented in source.
setPort
alias setPort = port
Undocumented in source.
setHost
alias setHost = host
Undocumented in source.
setUserInfo
alias setUserInfo = userinfo
Undocumented in source.
setQuery
alias setQuery = query
Undocumented in source.
setPath
alias setPath = path
Undocumented in source.
setFragment
alias setFragment = fragment
Undocumented in source.
InvalidPort
anonymousenum InvalidPort
Undocumented in source.
defaultPort
int defaultPort(cstring scheme)

Return the default port for the given scheme. InvalidPort is returned if the scheme is unknown, or does not accept a port.

getNormalizedScheme
cstring getNormalizedScheme(mstring buffer)

Return the parsed scheme, or null if the scheme was not specified. Automatically normalizes the scheme (converts to lower case)

scheme
cstring scheme()

Return the parsed scheme, or null if the scheme was not specified.

host
cstring host()

Return the parsed host, or null if the host was not specified

port
int port()

Return the parsed port number, or InvalidPort if the port was not provided.

validPort
int validPort()

Return a valid port number by performing a lookup on the known schemes if the port was not explicitly specified.

userinfo
cstring userinfo()

Return the parsed userinfo, or null if userinfo was not provided.

path
cstring path()

Return the parsed path, or null if the path was not provided.

query
cstring query()

Return the parsed query, or null if a query was not provided.

fragment
cstring fragment()

Return the parsed fragment, or null if a fragment was not provided.

isGeneric
bool isGeneric()

Return whether or not the UriView scheme is considered generic.

toString
istring toString()

Emit the content of this UriView. Output is constructed per RFC 2396.

Examples

auto s_uri = "http://example.net/magic?arg&arg#id";
auto uri = new Uri(s_uri);

test!("==")(uri.scheme, "http");
test!("==")(uri.host, "example.net");
test!("==")(uri.port, Uri.InvalidPort);

Buffer!(char) buffer;
uri.produce(buffer);
test!("==") (buffer[], s_uri);

Meta