Static Public Member Functions | Static Public Attributes | List of all members
kvikio::detail::UrlEncoder Class Reference

Provides URL encoding functionality. More...

#include <url.hpp>

Static Public Member Functions

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. More...
 

Static Public Attributes

static constexpr char aws_special_chars []
 Default set of special characters requiring encoding in AWS URLs. More...
 

Detailed Description

Provides URL encoding functionality.

The AWS object naming documentation (https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-keys.html) lists several types of special characters. In practice, handling them using libcurl is complex and described below.

Definition at line 390 of file url.hpp.

Member Function Documentation

◆ encode_path()

static std::string kvikio::detail::UrlEncoder::encode_path ( std::string_view  path,
std::string_view  chars_to_encode = std::string_view{ aws_special_chars, sizeof(aws_special_chars)} 
)
static

Percent-encodes specified characters in a URL path.

Performs percent-encoding (RFC 3986) on a given path string, encoding only the characters specified in the chars_to_encode parameter. Each encoded character is replaced with its percent-encoded equivalent (XX where XX is the hexadecimal representation of the character).

Only ASCII characters (0-127) are supported for encoding. Non-ASCII characters in chars_to_encode will be encoded to an empty string. Characters not in chars_to_encode are passed through unchanged.

Parameters
pathThe path string to encode
chars_to_encodeSet of characters that should be encoded (defaults to aws_special_chars)
Returns
A new string with specified characters percent-encoded
// Example usage with default AWS special characters
std::string encoded = UrlEncoder::encode_path("/path/ with spaces");
// Result: "/path/%20with%20spaces"
// Example with custom character set
std::string encoded = UrlEncoder::encode_path("hello/world", "/");
// Result: "hello%2Fworld"
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.

Member Data Documentation

◆ aws_special_chars

constexpr char kvikio::detail::UrlEncoder::aws_special_chars[]
staticconstexpr
Initial value:
= {
'!', '*', '\'', '(', ')', '&', '$', '@', '=', ';', ':', '+',
' ', ',', '?', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x07', '\x08',
'\x09', '\x0A', '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12', '\x13', '\x14',
'\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D', '\x1E', '\x1F', '\x7F'}

Default set of special characters requiring encoding in AWS URLs.

Definition at line 395 of file url.hpp.


The documentation for this class was generated from the following file: