azure-core
Public Member Functions | Static Public Member Functions | List of all members
Azure::Core::Url Class Referencefinal

Represents the location where a request will be performed. More...

#include <url.hpp>

Public Member Functions

 Url ()
 Constructs a new, empty URL object. More...
 
 Url (const std::string &encodedUrl)
 Constructs a URL from a URL-encoded string. More...
 
void SetScheme (const std::string &scheme)
 Sets URL scheme. More...
 
void SetHost (const std::string &encodedHost)
 Sets URL host. More...
 
void SetPort (uint16_t port)
 Sets URL port. More...
 
void SetPath (const std::string &encodedPath)
 Sets URL path. More...
 
void SetQueryParameters (std::map< std::string, std::string > queryParameters)
 Sets the query parameters from an existing query parameter map. More...
 
void AppendPath (const std::string &encodedPath)
 Appends an element of URL path. More...
 
void AppendQueryParameter (const std::string &encodedKey, const std::string &encodedValue)
 The value of a query parameter is expected to be non-URL-encoded and, by default, it will be encoded before adding to the URL. Use isValueEncoded = true when the value is already encoded. More...
 
void RemoveQueryParameter (const std::string &encodedKey)
 Removes an existing query parameter. More...
 
const std::string & GetHost () const
 Gets URL host. More...
 
const std::string & GetPath () const
 Gets the URL path. More...
 
uint16_t GetPort () const
 Gets the port number set for the URL. More...
 
std::map< std::string, std::string > GetQueryParameters () const
 Gets a copy of the list of query parameters from the URL. More...
 
const std::string & GetScheme () const
 Gets the URL scheme. More...
 
std::string GetRelativeUrl () const
 Gets the path and query parameters. More...
 
std::string GetAbsoluteUrl () const
 Gets Scheme, host, path and query parameters. More...
 

Static Public Member Functions

static std::string Decode (const std::string &value)
 Decodes value by transforming all escaped characters to it's non-encoded value. More...
 
static std::string Encode (const std::string &value, const std::string &doNotEncodeSymbols="")
 Encodes value by escaping characters to the form of HH where HH are hex digits. More...
 

Detailed Description

It can be parsed and initialized from a string that contains all URL components (scheme, host, path, etc.). Authority is not currently supported.

Constructor & Destructor Documentation

◆ Url() [1/2]

Azure::Core::Url::Url ( )
inline

◆ Url() [2/2]

Url::Url ( const std::string &  encodedUrl)
explicit
Parameters
encodedUrlA URL-encoded string.
Note
encodedUrl is expected to have all parts URL-encoded.

Member Function Documentation

◆ AppendPath()

void Azure::Core::Url::AppendPath ( const std::string &  encodedPath)
inline
Parameters
encodedPathURL path element to append, already encoded.

◆ AppendQueryParameter()

void Azure::Core::Url::AppendQueryParameter ( const std::string &  encodedKey,
const std::string &  encodedValue 
)
inline
Note
Overrides the value of existing query parameters.
Parameters
encodedKeyName of the query parameter, already encoded.
encodedValueValue of the query parameter, already encoded.

◆ Decode()

std::string Url::Decode ( const std::string &  value)
static
Parameters
valueURL-encoded string.
Returns
std::string with non-URL encoded values.

◆ Encode()

std::string Url::Encode ( const std::string &  value,
const std::string &  doNotEncodeSymbols = "" 
)
static
Note
doNotEncodeSymbols arg can be used to explicitly ask this function to skip characters from encoding. For instance, using this = - input would prevent encoding =, and -.
Parameters
valueNon URL-encoded string.
doNotEncodeSymbolsA string consisting of characters that do not need to be encoded.
Returns
std::string

◆ GetAbsoluteUrl()

std::string Url::GetAbsoluteUrl ( ) const
Returns
Absolute URL with URL-encoded query parameters.

◆ GetHost()

const std::string& Azure::Core::Url::GetHost ( ) const
inline

◆ GetPath()

const std::string& Azure::Core::Url::GetPath ( ) const
inline
Returns
const std::string&

◆ GetPort()

uint16_t Azure::Core::Url::GetPort ( ) const
inline
Note
If the port was not set for the URL, the returned port is 0. An HTTP request cannot be performed to port zero, an HTTP client is expected to set the default port depending on the request's schema when the port was not defined in the URL.
Returns
The port number from the URL.

◆ GetQueryParameters()

std::map<std::string, std::string> Azure::Core::Url::GetQueryParameters ( ) const
inline
Note
The query parameters are URL-encoded.
Returns
A copy of the query parameters map.

◆ GetRelativeUrl()

std::string Url::GetRelativeUrl ( ) const
Returns
Relative URL with URL-encoded query parameters.

◆ GetScheme()

const std::string& Azure::Core::Url::GetScheme ( ) const
inline

◆ RemoveQueryParameter()

void Azure::Core::Url::RemoveQueryParameter ( const std::string &  encodedKey)
inline
Parameters
encodedKeyThe name of the query parameter to be removed.

◆ SetHost()

void Azure::Core::Url::SetHost ( const std::string &  encodedHost)
inline
Parameters
encodedHostURL host, already encoded.

◆ SetPath()

void Azure::Core::Url::SetPath ( const std::string &  encodedPath)
inline
Parameters
encodedPathURL path, already encoded.

◆ SetPort()

void Azure::Core::Url::SetPort ( uint16_t  port)
inline
Parameters
portURL port.

◆ SetQueryParameters()

void Azure::Core::Url::SetQueryParameters ( std::map< std::string, std::string >  queryParameters)
inline
Note
Keys and values in queryParameters are expected to be URL-encoded.
Parameters
queryParametersquery parameters for request.

◆ SetScheme()

void Azure::Core::Url::SetScheme ( const std::string &  scheme)
inline
Parameters
schemeURL scheme.

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