Skip to content

EntropyEngine::Networking::WebDAV::Utils

Name
std::stringstripSchemeHost(std::string_view href)
Strips scheme and authority from URL.
std::stringpercentEncode(std::string_view s, bool keepSlashes =true)
Percent-encodes a string for use in URLs.
std::optional< std::string >percentDecode(std::string_view s)
Percent-decodes a URL-encoded string.
std::optional< std::chrono::system_clock::time_point >parseHttpDate(const char * s)
Parses HTTP date header (IMF-fixdate format).
std::stringnormalizeHrefForCompare(const std::string & href, bool ensureTrailingSlashIfCollection =false)
Normalizes href for string comparison.
std::string stripSchemeHost(
std::string_view href
)

Strips scheme and authority from URL.

Parameters:

  • href URL with scheme and host

Return: Path portion (e.g., “/dav/file.txt”)

Removes http[s]://host[:port] prefix, leaving only path and beyond. Used to extract path from absolute WebDAV hrefs.

auto path = stripSchemeHost("https://example.com/dav/file.txt"); // "/dav/file.txt"
std::string percentEncode(
std::string_view s,
bool keepSlashes =true
)

Percent-encodes a string for use in URLs.

Parameters:

  • s String to encode
  • keepSlashes If true, preserves ’/’ characters unencoded

Return: Percent-encoded string

Encodes unsafe characters as XX. When keepSlashes is true, ’/’ characters are preserved (useful for path components). Follows RFC 3986.

auto encoded = percentEncode("my file.txt"); // "my%20file.txt"
auto path = percentEncode("path/to/file", true); // "path/to/file" (slashes preserved)
std::optional< std::string > percentDecode(
std::string_view s
)

Percent-decodes a URL-encoded string.

Parameters:

  • s String to decode

Return: Decoded string, or nullopt if malformed

Decodes XX sequences back to original characters. Returns nullopt if string contains malformed encoding (e.g., ZZ, incomplete X).

auto decoded = percentDecode("my%20file.txt"); // "my file.txt"
auto bad = percentDecode("invalid%ZZ"); // nullopt
std::optional< std::chrono::system_clock::time_point > parseHttpDate(
const char * s
)

Parses HTTP date header (IMF-fixdate format).

Parameters:

  • s Date string in IMF-fixdate format

Return: Time point, or nullopt if parsing failed

Parses dates in IMF-fixdate format per RFC 7231 (e.g., “Mon, 15 Jan 2024 12:30:00 GMT”). Used for parsing Last-Modified headers from WebDAV responses.

auto date = parseHttpDate("Mon, 15 Jan 2024 12:30:00 GMT");
if (date) {
auto time_t = std::chrono::system_clock::to_time_t(*date);
// ...
}
std::string normalizeHrefForCompare(
const std::string & href,
bool ensureTrailingSlashIfCollection =false
)

Normalizes href for string comparison.

Parameters:

  • href URL to normalize
  • ensureTrailingSlashIfCollection If true, adds trailing ’/’ if not present

Return: Normalized path for comparison

Performs multiple normalizations:

  • Strips scheme and host
  • Drops query string and fragment
  • Collapses multiple consecutive ’/’ to single ’/’
  • Optionally adds trailing ’/’ for collections

Used to match hrefs from WebDAV responses against expected paths.

auto norm = normalizeHrefForCompare("http://example.com/dav//folder?q=1"); // "/dav/folder"
auto dir = normalizeHrefForCompare("/folder", true); // "/folder/"

Updated on 2026-01-26 at 17:14:35 -0500