Davix::Uri Class Reference

Uri parser. More...

`#include <davix_uri.hpp>`

## Public Member Functions

| Uri ()
| Construct an empty invalid Uri.
| Uri (const std::string &uri_string)
| construct a new Davix Uri from a string URL
| Uri (const Uri &uri)
| Copy constructor.
Uri & | operator= (const Uri &orig)
| assignment operator
void | addQueryParam (const std::string &key, const std::string &value)
void | addFragmentParam (const std::string &key, const std::string &value)
void | addPathSegment (const std::string &seg)
void | ensureTrailingSlash ()
| ensure that the path ends with a trailing slash
void | removeTrailingSlash ()
| remove the path's trailing slash, if it exists
bool | queryParamExists (const std::string &param) const
| check if the given query parameter exists
bool | fragmentParamExists (const std::string &param) const
| check if the given fragment parameter exists
const std::string | getFragmentParam (const std::string &param) const
| get the value of a fragment parameter
const std::string & | getString () const
int | getPort () const
const std::string & | getProtocol () const
const std::string & | getHost () const
const std::string & | getPath () const
void | setPath (const std::string &path)
void | setProtocol (const std::string &protocol)
void | httpizeProtocol ()
const std::string & | getUserInfo () const
const std::string & | getPathAndQuery () const
const std::string & | getFragment () const
const std::string & | getQuery () const
ParamVec | getQueryVec () const
StatusCode::Code | getStatus () const
bool | equal (const Uri &u1) const
| test if two URI are equals
bool | operator== (const Uri &u2) const
| compare oepration

## Static Public Member Functions

static std::string | join (const std::string &left, const std::string &right)
| Join two paths.
static std::string | escapeString (const std::string &str)
| Escape string.
static std::string | unescapeString (const std::string &str)
| Unescape urI.
static std::string | queryParamEscape (const std::string &str)
| Escape query parameter.
static Uri | fromRelativePath (const Uri &uri, const std::string &relPath)
| create a new Uri from URI and a relative associated path

## Detailed Description

Uri parser.

convenience class for uri parsing

Uri myuri("https://johnsmith:12345678@example.org:443/myfolder/myfile?type=personal#overthere");
cout << "Full uri: " << myuri.getString() << endl <<
"Port: " << myuri.getPort() << endl <<
"Protocol: " << myuri.getProtocol() << endl <<
"Host: " << myuri.getHost() << endl <<
"Path: " << myuri.getPath() << endl <<
"Query: " << myuri.getQuery() << endl <<
"Path and query: " << myuri.getPathAndQuery() << endl <<
"User info: " << myuri.getUserInfo() << endl;
/*
Output:
Full uri: https://johnsmith:12345678@example.org:443/myfolder/myfile?type=personal#overthere
Port: 443
Protocol: https
Host: example.org
Path: /myfolder/myfile
Query: type=personal
Path and query: /myfolder/myfile?type=personal
User info: johnsmith:12345678
*/

## Member Function Documentation

## addFragmentParam()

void Davix::Uri::addFragmentParam | ( | const std::string & | key,
|  | const std::string & | value )

append a fragment parameter to the uri

Parameters

  key | : key
  value | : value

## addPathSegment()

void Davix::Uri::addPathSegment | ( | const std::string & | seg | ) |

append a path segment to the uri

Parameters

  seg | : the segment to add

## addQueryParam()

void Davix::Uri::addQueryParam | ( | const std::string & | key,
|  | const std::string & | value )

append a query parameter to the uri

Parameters

  key | : parameter key, not escaped
  value | : parameter value, not escaped

## equal()

bool Davix::Uri::equal | ( | const Uri & | u1 | ) | const

test if two URI are equals

Parameters

  u1 |

Returns
  true if equal, else false

References Uri().

## escapeString()

std::string Davix::Uri::escapeString | ( | const std::string & | str | ) |

static

Escape string.

Parameters

  str | URL to escape

Returns
  encoded string

## fromRelativePath()

Uri Davix::Uri::fromRelativePath | ( | const Uri & | uri,
|  | const std::string & | relPath )

static

create a new Uri from URI and a relative associated path

Parameters

  uri | original URI
  relPath | relative path

Returns
  new URI from this path

References Uri().

## getFragment()

const std::string & Davix::Uri::getFragment | ( |  | ) | const

get the fragment part of the uri

Returns
  return the fragment part or an empty string if it does not exist

## getHost()

const std::string & Davix::Uri::getHost | ( |  | ) | const

get the host name

Returns
  return the hostname or an empty string if error

## getPath()

const std::string & Davix::Uri::getPath | ( |  | ) | const

get the path part of the Uri

Returns
  return the path of the Uri or an empty string if error

## getPathAndQuery()

const std::string & Davix::Uri::getPathAndQuery | ( |  | ) | const

get a concatenation of the path and the query argument of the URI

Returns
  return a path + query arguments concatenation or an empty string if error

## getPort()

int Davix::Uri::getPort | ( |  | ) | const

get the port number

Returns
  return the prot number of 0 if unspecified

## getProtocol()

const std::string & Davix::Uri::getProtocol | ( |  | ) | const

get the protocol scheme

Returns
  return the protocol scheme or an empty string if error

## getQuery()

const std::string & Davix::Uri::getQuery | ( |  | ) | const

get the query argument part of the uri

Returns
  return the query path string or an empty string if not exist or if error

## getStatus()

StatusCode::Code Davix::Uri::getStatus | ( |  | ) | const

Status of the Uri see StatusCode::Code

Returns
  StatusCode::OK if success or StatusCode::UriParsingError if error

## getString()

const std::string & Davix::Uri::getString | ( |  | ) | const

get a string representation of the full uri

Returns
  return the path or an empty string if error

## getUserInfo()

const std::string & Davix::Uri::getUserInfo | ( |  | ) | const

gextract user information from the URI

Returns
  return the path of the Uri or an empty string if error

## join()

std::string Davix::Uri::join | ( | const std::string & | left,
|  | const std::string & | right )

static

Join two paths.

Parameters

  left | URL or filesystem path

Returns
  The join of left and right, correctly escaped if left is a URL

## operator=()

Uri & Davix::Uri::operator= | ( | const Uri & | orig | ) |

assignment operator

Parameters

  orig |

Returns

References Uri().

## operator==()

bool Davix::Uri::operator== | ( | const Uri & | u2 | ) | const

compare oepration

Parameters

  u2 |

Returns
  true if u2 == current uri

References Uri().

## queryParamEscape()

std::string Davix::Uri::queryParamEscape | ( | const std::string & | str | ) |

static

Escape query parameter.

Parameters

  str | to escape

Returns
  encoded string

## unescapeString()

std::string Davix::Uri::unescapeString | ( | const std::string & | str | ) |

static

Unescape urI.

Parameters

  str | URL to escape

Returns
  unencoded string

The documentation for this class was generated from the following file:

- /build/davix-EuTrY8/davix-0.8.10/include/davix/utils/davix_uri.hpp