10 #include <curl/curl.h>
12 namespace kvikio::detail {
22 CURLU* _handle{
nullptr};
89 std::optional<std::string>
host;
96 std::optional<std::string>
port;
102 std::optional<std::string>
path;
152 std::optional<unsigned int> bitmask_url_flags = std::nullopt,
153 std::optional<unsigned int> bitmask_component_flags = std::nullopt);
168 std::optional<unsigned int> bitmask_component_flags = std::nullopt,
169 std::optional<CURLUcode> allowed_err_code = std::nullopt);
183 std::string
const& url,
185 std::optional<unsigned int> bitmask_url_flags = std::nullopt,
186 std::optional<unsigned int> bitmask_component_flags = std::nullopt,
187 std::optional<CURLUcode> allowed_err_code = std::nullopt);
231 std::optional<unsigned int> flags = std::nullopt);
251 std::optional<unsigned int> bitmask_url_flags = std::nullopt);
261 std::optional<unsigned int> bitmask_url_flags = std::nullopt);
362 std::string
build(std::optional<unsigned int> bitmask_component_flags = std::nullopt)
const;
395 static constexpr
char aws_special_chars[] = {
396 '!',
'*',
'\'',
'(',
')',
'&',
'$',
'@',
'=',
';',
':',
'+',
397 ' ',
',',
'?',
'\x00',
'\x01',
'\x02',
'\x03',
'\x04',
'\x05',
'\x06',
'\x07',
'\x08',
398 '\x09',
'\x0A',
'\x0B',
'\x0C',
'\x0D',
'\x0E',
'\x0F',
'\x10',
'\x11',
'\x12',
'\x13',
'\x14',
399 '\x15',
'\x16',
'\x17',
'\x18',
'\x19',
'\x1A',
'\x1B',
'\x1C',
'\x1D',
'\x1E',
'\x1F',
'\x7F'};
428 std::string_view chars_to_encode = std::string_view{
429 aws_special_chars,
sizeof(aws_special_chars)});
RAII wrapper for libcurl's URL handle (CURLU)
~CurlUrlHandle() noexcept
Clean up the underlying URL handle.
CURLU * get() const
Get the underlying libcurl URL handle.
CurlUrlHandle()
Create a new libcurl URL handle.
URL builder utility using libcurl's URL API.
UrlBuilder & set_host(std::optional< std::string > const &host)
Set the hostname or IP address.
UrlBuilder & set_fragment(std::optional< std::string > const &fragment)
Set the fragment identifier.
UrlBuilder(std::string const &url, std::optional< unsigned int > bitmask_url_flags=std::nullopt)
Construct a URL builder from an existing URL string.
UrlBuilder & set_scheme(std::optional< std::string > const &scheme)
Set the URL scheme (e.g., "http", "https", "ftp")
UrlBuilder(UrlParser::UrlComponents const &components, std::optional< unsigned int > bitmask_url_flags=std::nullopt)
Construct a URL builder from parsed URL components.
UrlBuilder & set_port(std::optional< std::string > const &port)
Set the port number.
UrlBuilder & set_path(std::optional< std::string > const &path)
Set the path component.
std::string build(std::optional< unsigned int > bitmask_component_flags=std::nullopt) const
Build the final URL string.
UrlBuilder()
Construct an empty URL builder.
UrlBuilder & set_query(std::optional< std::string > const &query)
Set the entire query string.
Provides URL encoding functionality.
static std::string encode_path(std::string_view path, std::string_view chars_to_encode=std::string_view{ aws_special_chars, sizeof(aws_special_chars)})
Percent-encodes specified characters in a URL path.
URL parsing utility using libcurl's URL API.
static std::optional< std::string > extract_component(std::string const &url, CURLUPart part, std::optional< unsigned int > bitmask_url_flags=std::nullopt, std::optional< unsigned int > bitmask_component_flags=std::nullopt, std::optional< CURLUcode > allowed_err_code=std::nullopt)
Extract a specific component from a URL string.
static UrlComponents parse(std::string const &url, std::optional< unsigned int > bitmask_url_flags=std::nullopt, std::optional< unsigned int > bitmask_component_flags=std::nullopt)
Parses the given URL according to RFC 3986 plus and extracts its components.
static std::optional< std::string > extract_component(CurlUrlHandle const &handle, CURLUPart part, std::optional< unsigned int > bitmask_component_flags=std::nullopt, std::optional< CURLUcode > allowed_err_code=std::nullopt)
Extract a specific component from a CurlUrlHandle.
Container for parsed URL components.
std::optional< std::string > host
The hostname or IP address. May be empty for URLs without an authority component (e....
std::optional< std::string > path
The path component of the URL. Libcurl ensures that the path component is always present,...
std::optional< std::string > scheme
The URL scheme (e.g., "http", "https", "ftp"). May be empty for scheme-relative URLs or paths.
std::optional< std::string > query
The query string (without the leading "?"). Empty if no query parameters are present.
std::optional< std::string > port
The port number as a string. Will be empty if no explicit port is specified in the URL.
std::optional< std::string > fragment
The fragment identifier (without the leading "#"). Empty if no fragment is present.