10Duke Enterprise C++ SDK
Loading...
Searching...
No Matches
tenduke::net::URLBuilder Class Reference

#include <URLBuilder.h>

Detailed Description

Very simple URL-builder.

IMPORTANT Unless specifically documented, URLBuilder does not decode / encode any parts of the URL (see documentation of tenduke::net::URL, which stores the components unencoded). The exception is the path, which tenduke::net::URL stores encoded: path() and appendPath() take an unencoded path and encode it, encodedPath() takes an already encoded path.

Public Member Functions

 URLBuilder (const ::tenduke::net::URLCodec &urls)
 Constructs a new instance.
 URLBuilder (const ::tenduke::net::URLCodec &urls, const ::tenduke::net::URL *url)
 Constructs a new instance, initializing fields from given URL.
::tenduke::net::URL build ()
 Builds the URL.
std::unique_ptr<::tenduke::net::URL > buildPtr ()
 Builds the URL into a pointer.
std::string buildString ()
 Builds the URL directly into a string.
URLBuilder & scheme (const char *scheme, std::size_t length)
URLBuilder & scheme (const std::string &scheme)
URLBuilder & username (const char *username, std::size_t length)
URLBuilder & username (const std::string &scheme)
URLBuilder & password (const char *password, std::size_t length)
URLBuilder & password (const std::string &password)
URLBuilder & hostname (const char *hostname, std::size_t length)
 Sets the hostname.
URLBuilder & hostname (const std::string &hostname)
 Sets the hostname.
URLBuilder & port (std::uint16_t port)
URLBuilder & path (const std::string &path)
 Sets the entire path: Overwrites any existing path.
URLBuilder & path (const char *path, std::size_t length)
 Sets the entire path: Overwrites any existing path.
URLBuilder & encodedPath (const std::string &encodedPath)
 Sets the entire path from an already encoded path: Overwrites any existing path.
URLBuilder & encodedPath (const char *encodedPath, std::size_t length)
 Sets the entire path from an already encoded path: Overwrites any existing path.
URLBuilder & fragment (const char *fragment, std::size_t length)
URLBuilder & fragment (const std::string &fragment)
URLBuilder & appendPath (const std::string &pathComponent)
 Appends a path component.
URLBuilder & baseURL (const ::tenduke::net::URL &url)
 Sets the base URL.
URLBuilder & queryParameter (const char *name)
 Adds query parameter without a value.
URLBuilder & queryParameter (const std::string &name)
 Adds query parameter without a value.
URLBuilder & queryParameter (const char *name, const char *value)
 Adds query parameter.
URLBuilder & queryParameter (const std::string &name, const std::string &value)
 Adds query parameter.
URLBuilder & queryParameter (const char *name, std::size_t length)
 Adds query parameter.
URLBuilder & queryParameter (const char *name, std::size_t nameLength, const char *value, std::size_t valueLength)
 Adds query parameter.
URLBuilder & queryParameters (const std::map< std::string, std::string > &pParameters)
 Sets multiple query parameters.
URLBuilder & encodedQueryParameter (const char *name, const char *value)
 Adds an encoded query parameter.
URLBuilder & encodedQueryParameter (const std::string &name, const std::string &value="")
 Adds an encoded query parameter.
URLBuilder & encodedQueryParameter (const char *name, std::size_t nameLength)
 Adds an encoded query parameter.
URLBuilder & encodedQueryParameter (const char *name, std::size_t nameLength, const char *value, std::size_t valueLength)
 Adds an encoded query parameter.
std::string pctEncode (const std::string &value) const
 Utility to PCT-encode a string.

Constructor & Destructor Documentation

◆ URLBuilder() [1/2]

tenduke::net::URLBuilder::URLBuilder ( const ::tenduke::net::URLCodec & urls)
explicit

Constructs a new instance.

Parameters
urls-

◆ URLBuilder() [2/2]

tenduke::net::URLBuilder::URLBuilder ( const ::tenduke::net::URLCodec & urls,
const ::tenduke::net::URL * url )

Constructs a new instance, initializing fields from given URL.

Parameters
urls-
url-

Member Function Documentation

◆ appendPath()

URLBuilder & tenduke::net::URLBuilder::appendPath ( const std::string & pathComponent)

Appends a path component.

This method automatically appends "/" as necessary.

The path component is unencoded and is encoded like in path(const std::string &).

Parameters
pathComponent
Returns
this instance for method-chaining

◆ baseURL()

xdnet::URLBuilder & tenduke::net::URLBuilder::baseURL ( const ::tenduke::net::URL & url)

Sets the base URL.

Initializes all the fields from the URL, overwriting any existing values.

Parameters
url-
Returns
this instance for method-chaining

◆ build()

URL tenduke::net::URLBuilder::build ( )

Builds the URL.

Returns
the URL

◆ buildPtr()

std::unique_ptr<::URL > tenduke::net::URLBuilder::buildPtr ( )

Builds the URL into a pointer.

Returns
the URL

◆ buildString()

std::string tenduke::net::URLBuilder::buildString ( )

Builds the URL directly into a string.

Returns
the URL as string, encoded as necessary.

◆ encodedPath() [1/2]

xdnet::URLBuilder & tenduke::net::URLBuilder::encodedPath ( const char * encodedPath,
std::size_t length )

Sets the entire path from an already encoded path: Overwrites any existing path.

See encodedPath(const std::string &).

Parameters
encodedPaththe encoded path
length-
Returns
this instance for method-chaining.

◆ encodedPath() [2/2]

xdnet::URLBuilder & tenduke::net::URLBuilder::encodedPath ( const std::string & encodedPath)

Sets the entire path from an already encoded path: Overwrites any existing path.

The path is stored as is, e.g. %2F stays an encoded slash and not a path separator. Characters which are not allowed in a URL path are percent-encoded (see tenduke::net::normalizeEncodedURLPath()).

Parameters
encodedPaththe encoded path
Returns
this instance for method-chaining.

◆ encodedQueryParameter() [1/4]

xdnet::URLBuilder & tenduke::net::URLBuilder::encodedQueryParameter ( const char * name,
const char * value )

Adds an encoded query parameter.

The caller has already encoded the parameter name and value: The method will decode them. As in application/x-www-form-urlencoded, + is decoded as a space (an encoded plus is %2B).

Parameters
namename of the parameter
valuevalue of the parameter
Returns
this instance for method-chaining

◆ encodedQueryParameter() [2/4]

xdnet::URLBuilder & tenduke::net::URLBuilder::encodedQueryParameter ( const char * name,
std::size_t nameLength )

Adds an encoded query parameter.

The caller has already encoded the parameter name: The method will decode it, + as a space.

Parameters
namename of the parameter
nameLengthlength of the parameter
Returns
this instance for method-chaining

◆ encodedQueryParameter() [3/4]

xdnet::URLBuilder & tenduke::net::URLBuilder::encodedQueryParameter ( const char * name,
std::size_t nameLength,
const char * value,
std::size_t valueLength )

Adds an encoded query parameter.

The caller has already encoded the parameter name and value: The method will decode them, + as a space.

Parameters
namename of the parameter
nameLengthlength of the parameter
valuevalue of the parameter. Optional. If not present, a parameter without value will be created.
valueLengthlength of the value
Returns
this instance for method-chaining

◆ encodedQueryParameter() [4/4]

xdnet::URLBuilder & tenduke::net::URLBuilder::encodedQueryParameter ( const std::string & name,
const std::string & value = "" )

Adds an encoded query parameter.

The caller has already encoded the parameter name and value: The method will decode them, + as a space.

Parameters
namename of the parameter
valuevalue of the parameter. Optional. If not present, a parameter without value will be created.
Returns
this instance for method-chaining

◆ hostname() [1/2]

xdnet::URLBuilder & tenduke::net::URLBuilder::hostname ( const char * hostname,
std::size_t length )

Sets the hostname.

Parameters
hostname-
length-
Exceptions
tenduke::net::MalformedURLExceptionif the hostname contains characters not allowed in a URL host

◆ hostname() [2/2]

xdnet::URLBuilder & tenduke::net::URLBuilder::hostname ( const std::string & hostname)

Sets the hostname.

Parameters
hostname-
Exceptions
tenduke::net::MalformedURLExceptionif the hostname contains characters not allowed in a URL host

◆ path() [1/2]

xdnet::URLBuilder & tenduke::net::URLBuilder::path ( const char * path,
std::size_t length )

Sets the entire path: Overwrites any existing path.

The path is unencoded, see path(const std::string &).

Parameters
paththe unencoded path
length-
Returns
this instance for method-chaining.

◆ path() [2/2]

xdnet::URLBuilder & tenduke::net::URLBuilder::path ( const std::string & path)

Sets the entire path: Overwrites any existing path.

The path is unencoded: / separates the path segments, all other characters except unreserved characters are percent-encoded (see tenduke::net::URLCodec::encodeURLPath()).

Parameters
paththe unencoded path
Returns
this instance for method-chaining.

◆ pctEncode()

std::string tenduke::net::URLBuilder::pctEncode ( const std::string & value) const

Utility to PCT-encode a string.

Parameters
value-
Returns
-

◆ queryParameter() [1/6]

xdnet::URLBuilder & tenduke::net::URLBuilder::queryParameter ( const char * name)

Adds query parameter without a value.

Parameters
name-
Returns
-

◆ queryParameter() [2/6]

xdnet::URLBuilder & tenduke::net::URLBuilder::queryParameter ( const char * name,
const char * value )

Adds query parameter.

Parameters
name-
value-
Returns
-

◆ queryParameter() [3/6]

xdnet::URLBuilder & tenduke::net::URLBuilder::queryParameter ( const char * name,
std::size_t length )

Adds query parameter.

Parameters
name-
length-
Returns
-

◆ queryParameter() [4/6]

xdnet::URLBuilder & tenduke::net::URLBuilder::queryParameter ( const char * name,
std::size_t nameLength,
const char * value,
std::size_t valueLength )

Adds query parameter.

Parameters
name-
nameLength-
value-
valueLength-
Returns
-

◆ queryParameter() [5/6]

xdnet::URLBuilder & tenduke::net::URLBuilder::queryParameter ( const std::string & name)

Adds query parameter without a value.

Parameters
name-
Returns
-

◆ queryParameter() [6/6]

xdnet::URLBuilder & tenduke::net::URLBuilder::queryParameter ( const std::string & name,
const std::string & value )

Adds query parameter.

Parameters
name-
value-
Returns
-

◆ queryParameters()

xdnet::URLBuilder & tenduke::net::URLBuilder::queryParameters ( const std::map< std::string, std::string > & pParameters)

Sets multiple query parameters.

Parameters
pParameters-
Returns
this instance for method-chaining

The documentation for this class was generated from the following files:
  • core/core/src/net/URLBuilder.h
  • core/core/src/net/URLBuilder.cpp