URL
URL
#include <icy/http/url.h>class URLDefined in src/http/include/icy/http/url.h:28
An RFC 3986 based URL parser. Constructors and assignment operators will throw a SyntaxException if the URL is invalid.
List of all members
| Name | Kind | Owner |
|---|---|---|
operator<< | friend | Declared here |
URL | function | Declared here |
URL | function | Declared here |
URL | function | Declared here |
URL | function | Declared here |
URL | function | Declared here |
URL | function | Declared here |
URL | function | Declared here |
~URL | function | Declared here |
operator= | function | Declared here |
operator= | function | Declared here |
operator= | function | Declared here |
parse | function | Declared here |
scheme | function | Declared here |
userInfo | function | Declared here |
host | function | Declared here |
port | function | Declared here |
authority | function | Declared here |
path | function | Declared here |
pathEtc | function | Declared here |
query | function | Declared here |
fragment | function | Declared here |
hasSchema | function | Declared here |
hasUserInfo | function | Declared here |
hasHost | function | Declared here |
hasPort | function | Declared here |
hasPath | function | Declared here |
hasQuery | function | Declared here |
hasFragment | function | Declared here |
valid | function | Declared here |
str | function | Declared here |
encode | function | Declared here |
decode | function | Declared here |
_buf | variable | Declared here |
_scheme | variable | Declared here |
_userInfo | variable | Declared here |
_host | variable | Declared here |
_port | variable | Declared here |
_path | variable | Declared here |
_query | variable | Declared here |
_fragment | variable | Declared here |
_hasPort | variable | Declared here |
Friends
| Name | Description |
|---|---|
operator<< inline |
operator<<
inline
friend inline std::ostream & operator<<(std::ostream & stream, const URL & url)Defined in src/http/include/icy/http/url.h:163
Public Methods
| Return | Name | Description |
|---|---|---|
URL | Creates an empty URL. | |
URL | Parses the URL from a null-terminated string. | |
URL | Parses the URL from a std::string. | |
URL | Constructs a URL from scheme and authority components. | |
URL | Constructs a URL from scheme, authority, and path+query+fragment. | |
URL | Constructs a URL from individual components. | |
URL | Defaulted constructor. | |
URL & | operator= | Assigns a URL from another URL instance. |
URL & | operator= | Assigns a URL from a null-terminated string. |
URL & | operator= | Assigns a URL from a std::string. |
bool | parse | Parses and assigns a URL from the given string view, resetting all components first. |
std::string | scheme const | Returns the URL scheme (e.g. "http", "https", "ws"). Always lowercase. |
std::string | userInfo const | Returns the user info component (e.g. "user:pass" from "http://user:pass@host/"). Returns an empty string if not present. |
std::string | host const | Returns the host component (e.g. "example.com"). Returns an empty string if not present. |
uint16_t | port const | Returns the port number. If no explicit port was in the URL, returns the default port for the scheme (80 for http, 443 for https), or 0 if the scheme is unknown. |
std::string | authority const | Returns the authority component (userinfo@host:port). Only includes components that are present. |
std::string | path const | Returns the path component (e.g. "/index.html"). Returns an empty string if not present. |
std::string | pathEtc const | Returns the path, query and fragment combined (e.g. "/path?q=1#frag"). |
std::string | query const | Returns the query string without the leading '?' (e.g. "key=value&foo=bar"). Returns an empty string if not present. |
std::string | fragment const | Returns the fragment identifier without the leading '#'. Returns an empty string if not present. |
bool | hasSchema const | Returns true if the URL has a scheme component. |
bool | hasUserInfo const | Returns true if the URL has a user info component. |
bool | hasHost const | Returns true if the URL has a host component. |
bool | hasPort const | Returns true if an explicit port was specified in the URL. |
bool | hasPath const | Returns true if the URL has a path component. |
bool | hasQuery const | Returns true if the URL has a query component. |
bool | hasFragment const | Returns true if the URL has a fragment component. |
bool | valid const | Returns true if the URL is non-empty and was successfully parsed. |
std::string | str const | Returns the original URL string as parsed. |
URL
URL()Defined in src/http/include/icy/http/url.h:32
Creates an empty URL.
URL
URL(const char * url)Defined in src/http/include/icy/http/url.h:36
Parses the URL from a null-terminated string.
Parameters
urlNull-terminated URL string to parse.
URL
URL(const std::string & url)Defined in src/http/include/icy/http/url.h:40
Parses the URL from a std::string.
Parameters
urlURL string to parse.
URL
URL(const std::string & scheme, const std::string & authority)Defined in src/http/include/icy/http/url.h:45
Constructs a URL from scheme and authority components.
Parameters
schemeURL scheme (e.g. "http", "https").authorityHost and optional port (e.g. "example.com:8080").
URL
URL(const std::string & scheme, const std::string & authority, const std::string & pathEtc)Defined in src/http/include/icy/http/url.h:51
Constructs a URL from scheme, authority, and path+query+fragment.
Parameters
schemeURL scheme (e.g. "http").authorityHost and optional port.pathEtcPath, query and fragment combined (e.g. "/path?q=1#frag").
URL
URL(const std::string & scheme, const std::string & authority, const std::string & path, const std::string & query, const std::string & fragment = "")Defined in src/http/include/icy/http/url.h:60
Constructs a URL from individual components.
Parameters
schemeURL scheme (e.g. "http").authorityHost and optional port.pathURL path (e.g. "/index.html").queryQuery string without leading '?' (e.g. "key=value").fragmentFragment identifier without leading '#'.
URL
URL(const URL &) = defaultDefined in src/http/include/icy/http/url.h:64
Defaulted constructor.
operator=
URL & operator=(const URL & uri)Defined in src/http/include/icy/http/url.h:70
Assigns a URL from another URL instance.
Parameters
uriSource URL to copy from.
Returns
Reference to this URL.
operator=
URL & operator=(const char * uri)Defined in src/http/include/icy/http/url.h:75
Assigns a URL from a null-terminated string.
Parameters
uriNull-terminated URL string to parse.
Returns
Reference to this URL.
operator=
URL & operator=(const std::string & uri)Defined in src/http/include/icy/http/url.h:80
Assigns a URL from a std::string.
Parameters
uriURL string to parse.
Returns
Reference to this URL.
parse
bool parse(std::string_view url, bool whiny = true)Defined in src/http/include/icy/http/url.h:86
Parses and assigns a URL from the given string view, resetting all components first.
Parameters
urlURL string to parse.whinyIf true, throws std::runtime_error on an invalid URL; otherwise returns false.
Returns
true if the URL was parsed successfully; false if invalid and whiny is false.
scheme
const
std::string scheme() constDefined in src/http/include/icy/http/url.h:102
Returns the URL scheme (e.g. "http", "https", "ws"). Always lowercase.
userInfo
const
std::string userInfo() constDefined in src/http/include/icy/http/url.h:106
Returns the user info component (e.g. "user:pass" from "http://user:pass@host/"). Returns an empty string if not present.
host
const
std::string host() constDefined in src/http/include/icy/http/url.h:110
Returns the host component (e.g. "example.com"). Returns an empty string if not present.
port
const
uint16_t port() constDefined in src/http/include/icy/http/url.h:115
Returns the port number. If no explicit port was in the URL, returns the default port for the scheme (80 for http, 443 for https), or 0 if the scheme is unknown.
authority
const
std::string authority() constDefined in src/http/include/icy/http/url.h:119
Returns the authority component (userinfo@host:port). Only includes components that are present.
path
const
std::string path() constDefined in src/http/include/icy/http/url.h:123
Returns the path component (e.g. "/index.html"). Returns an empty string if not present.
pathEtc
const
std::string pathEtc() constDefined in src/http/include/icy/http/url.h:126
Returns the path, query and fragment combined (e.g. "/path?q=1#frag").
query
const
std::string query() constDefined in src/http/include/icy/http/url.h:130
Returns the query string without the leading '?' (e.g. "key=value&foo=bar"). Returns an empty string if not present.
fragment
const
std::string fragment() constDefined in src/http/include/icy/http/url.h:134
Returns the fragment identifier without the leading '#'. Returns an empty string if not present.
hasSchema
const
bool hasSchema() constDefined in src/http/include/icy/http/url.h:137
Returns true if the URL has a scheme component.
hasUserInfo
const
bool hasUserInfo() constDefined in src/http/include/icy/http/url.h:140
Returns true if the URL has a user info component.
hasHost
const
bool hasHost() constDefined in src/http/include/icy/http/url.h:143
Returns true if the URL has a host component.
hasPort
const
bool hasPort() constDefined in src/http/include/icy/http/url.h:146
Returns true if an explicit port was specified in the URL.
hasPath
const
bool hasPath() constDefined in src/http/include/icy/http/url.h:149
Returns true if the URL has a path component.
hasQuery
const
bool hasQuery() constDefined in src/http/include/icy/http/url.h:152
Returns true if the URL has a query component.
hasFragment
const
bool hasFragment() constDefined in src/http/include/icy/http/url.h:155
Returns true if the URL has a fragment component.
valid
const
bool valid() constDefined in src/http/include/icy/http/url.h:158
Returns true if the URL is non-empty and was successfully parsed.
str
const
std::string str() constDefined in src/http/include/icy/http/url.h:161
Returns the original URL string as parsed.
Public Static Methods
| Return | Name | Description |
|---|---|---|
std::string | encode static | Percent-encodes a string per RFC 3986, preserving unreserved characters (A-Z, a-z, 0-9, '-', '_', '.', '~'). Equivalent to JavaScript's encodeURIComponent(). |
std::string | decode static | Decodes a percent-encoded string per RFC 3986. Equivalent to JavaScript's decodeURIComponent(). |
encode
static
static std::string encode(std::string_view str)Defined in src/http/include/icy/http/url.h:92
Percent-encodes a string per RFC 3986, preserving unreserved characters (A-Z, a-z, 0-9, '-', '_', '.', '~'). Equivalent to JavaScript's encodeURIComponent().
Parameters
strInput string to encode.
Returns
Percent-encoded string.
decode
static
static std::string decode(std::string_view str)Defined in src/http/include/icy/http/url.h:98
Decodes a percent-encoded string per RFC 3986. Equivalent to JavaScript's decodeURIComponent().
Parameters
strPercent-encoded input string.
Returns
Decoded string.
Protected Attributes
| Return | Name | Description |
|---|---|---|
std::string | _buf | |
std::string | _scheme | |
std::string | _userInfo | |
std::string | _host | |
uint16_t | _port | |
std::string | _path | |
std::string | _query | |
std::string | _fragment | |
bool | _hasPort |
_buf
std::string _bufDefined in src/http/include/icy/http/url.h:170
_scheme
std::string _schemeDefined in src/http/include/icy/http/url.h:171
_userInfo
std::string _userInfoDefined in src/http/include/icy/http/url.h:172
_host
std::string _hostDefined in src/http/include/icy/http/url.h:173
_port
uint16_t _portDefined in src/http/include/icy/http/url.h:174
_path
std::string _pathDefined in src/http/include/icy/http/url.h:175
_query
std::string _queryDefined in src/http/include/icy/http/url.h:176
_fragment
std::string _fragmentDefined in src/http/include/icy/http/url.h:177
_hasPort
bool _hasPort