Represents an immutable Uniform Resource Locator.
A Uniform Resource Locator (URL), is used to uniquely identify a resource on the Internet. The URL is a compact text string with a restricted syntax that consists of four main components:
constexpr std::string_view protocol() const noexcept
Gets the protocol of the URL.
Definition zdbpp.h:402
The protocol
part is mandatory, the other components may or may not be present in an URL string. For instance the file
protocol only use the path component while a http
protocol may use all components.
The following URL components are automatically unescaped according to the escaping mechanism defined in RFC 2396; credentials
, path
and parameter values
. If you use a password with non-URL safe characters, you must URL escape the value.
An IPv6 address can be used for host as defined in RFC2732 by enclosing the address in [brackets]. For instance, mysql://[2010:836B:4179::836B:4179]:3306/test
For more information about the URL syntax and specification, see, RFC2396 - Uniform Resource Identifiers (URI): Generic Syntax
Example:
URL url(
"postgresql://user:password@example.com:5432/database?use-ssl=true");
std::cout << "Protocol: " << url.protocol() << std::endl;
std::cout << "Host: " << url.host().value_or("Not specified") << std::endl;
std::cout << "Port: " << url.port() << std::endl;
std::cout << "User: " << url.user().value_or("Not specified") << std::endl;
std::cout << "Password: " << (url.password().has_value() ? "Specified" : "Not specified") << std::endl;
std::cout << "Path: " << url.path().value_or("Not specified") << std::endl;
auto use_ssl = url.parameter("use-ssl").value_or("false");
std::cout << "SSL Enabled: " << (use_ssl == "true") << std::endl;
Represents an immutable Uniform Resource Locator.
Definition zdbpp.h:333
|
| URL (const std::string &url) |
| Creates a new URL object from the given URL string.
|
|
|
constexpr std::string_view | protocol () const noexcept |
| Gets the protocol of the URL.
|
|
constexpr std::optional< std::string_view > | user () const noexcept |
| Gets the username from the URL's authority part.
|
|
constexpr std::optional< std::string_view > | password () const noexcept |
| Gets the password from the URL's authority part.
|
|
constexpr std::optional< std::string_view > | host () const noexcept |
| Gets the hostname of the URL.
|
|
constexpr int | port () const noexcept |
| Gets the port of the URL.
|
|
constexpr std::optional< std::string_view > | path () const noexcept |
| Gets the path of the URL.
|
|
constexpr std::optional< std::string_view > | queryString () const noexcept |
| Gets the query string of the URL.
|
|
std::vector< std::string_view > | parameterNames () const noexcept |
| Gets the names of parameters contained in this URL.
|
|
std::optional< std::string_view > | parameter (const std::string &name) const noexcept |
| Gets the value of the specified URL parameter.
|
|
|
constexpr std::string_view | toString () const noexcept |
| Returns a string representation of this URL object.
|
|