URLSpec
-
class URLSpec
A container for a URL, e.g. “http://server:port/path”.
The URLSpec object is similar to a Filename in that it contains logic to identify the various parts of a URL and return (or modify) them separately.
Inheritance diagram
-
URLSpec(void)
-
URLSpec(std::string const &url, bool server_name_expected = false)
-
URLSpec(URLSpec const&) = default
Creates a
URLSpec
by appending a path to the end of the oldURLSpec
, inserting an intervening forward slash if necessary.
-
char const *c_str(void) const
-
int compare_to(URLSpec const &other) const
Returns a number less than zero if this
URLSpec
sorts before the other one, greater than zero if it sorts after, or zero if they are equivalent.
-
bool empty(void) const
Returns false if the
URLSpec
is valid (not empty), or true if it is an empty string.
-
std::string get_authority(void) const
Returns the authority specified by the URL (this includes username, server, and/or port), or empty string if no authority is specified.
-
static int get_default_port_for_scheme(std::string const &scheme)
Returns the default port number for the indicated scheme, or 0 if there is no known default.
-
std::size_t get_hash(void) const
-
std::string get_path(void) const
Returns the path specified by the URL, or “/” if no path is specified.
-
std::string get_path_and_query(void) const
Returns the path (or “/” if no path is specified), followed by the query if it is specified.
-
uint16_t get_port(void) const
Returns the port number specified by the URL, or the default port if not specified.
-
std::string get_port_str(void) const
Returns the port specified by the URL as a string, or the empty string if no port is specified. Compare this with
get_port()
, which returns a default port number if no port is specified.
-
std::string get_query(void) const
Returns the query specified by the URL, or empty string if no query is specified.
-
std::string get_scheme(void) const
Returns the scheme specified by the URL, or empty string if no scheme is specified.
-
std::string get_server(void) const
Returns the server name specified by the URL, if any. In case of an IPv6 address, does not include the enclosing brackets.
-
std::string get_server_and_port(void) const
Returns a string consisting of the server name, followed by a colon, followed by the port number. If the port number is not explicitly given in the URL, this string will include the implicit port number. If the server is an IPv6 address, it will be enclosed in square brackets.
-
std::string const &get_url(void) const
Returns the complete URL specification.
-
std::string get_username(void) const
Returns the username specified by the URL, if any. This might also include a password, e.g. “username:password”, although putting a password on the URL is probably a bad idea.
-
bool has_authority(void) const
Returns true if the URL specifies an authority (this includes username, server, and/or port), false otherwise.
-
bool has_path(void) const
Returns true if the URL includes a path specification (that is, the particular filename on the server to retrieve), false otherwise.
-
bool has_port(void) const
Returns true if the URL specifies a port number, false otherwise.
-
bool has_query(void) const
Returns true if the URL includes a query specification, false otherwise.
-
bool has_scheme(void) const
Returns true if the URL specifies a scheme (e.g. “http:”), false otherwise.
-
bool has_server(void) const
Returns true if the URL specifies a server name, false otherwise.
-
bool has_username(void) const
Returns true if the URL specifies a username (and/or password), false otherwise.
-
bool input(std::istream &in)
-
bool is_default_port(void) const
Returns true if the port number encoded in this URL is the default port number for the scheme (or if there is no port number), or false if it is a nonstandard port.
-
bool is_ssl(void) const
Returns true if the URL’s scheme specifies an SSL-secured protocol such as https, or false otherwise.
-
std::size_t length(void) const
-
void output(std::ostream &out) const
-
static std::string quote(std::string const &source, std::string const &safe = "/")
Returns the source string with all “unsafe” characters quoted, making a string suitable for placing in a URL. Letters, digits, and the underscore, comma, period, and hyphen characters, as well as any included in the safe string, are left alone; all others are converted to hex representation.
-
static std::string quote_plus(std::string const &source, std::string const &safe = "/")
Behaves like
quote()
with the additional behavior of replacing spaces with plus signs.
-
void set_authority(std::string const &authority)
Replaces the authority part of the URL specification. This includes the username, server, and port.
-
void set_path(std::string const &path)
Replaces the path part of the URL specification.
-
void set_port(std::string const &port)
-
void set_port(uint16_t port)
Replaces the port part of the URL specification.
Replaces the port part of the URL specification, given a numeric port number.
-
void set_query(std::string const &query)
Replaces the query part of the URL specification.
-
void set_scheme(std::string const &scheme)
Replaces the scheme part of the URL specification.
-
void set_server(std::string const &server)
Replaces the server part of the URL specification. Unlike
set_server_and_port
, this method does not require IPv6 addresses to be enclosed in square brackets.
-
void set_server_and_port(std::string const &server_and_port)
Replaces the server and port parts of the URL specification simultaneously. The input string should be of the form “server:port”, or just “server” to make the port number implicit. Any IPv6 address must be enclosed in square brackets.
-
void set_url(std::string const &url, bool server_name_expected = false)
Completely replaces the URL with the indicated string. If server_name_expected is true, it is a hint that an undecorated URL is probably a server name, not a local filename.
-
void set_username(std::string const &username)
Replaces the username part of the URL specification.
-
std::size_t size(void) const
-
static std::string unquote(std::string const &source)
Reverses the operation of quote(): converts escaped characters of the form “%xx” to their ascii equivalent.
-
static std::string unquote_plus(std::string const &source)
Reverses the operation of quote_plus(): converts escaped characters of the form “%xx” to their ascii equivalent, and also converts plus signs to spaces.
-
URLSpec(void)