microserve.handler module

Files

file handler.cppm

Classes

class microserve::FileHandler
Serves static files and reverse-proxies configured locations.
struct microserve::FileHandler::CacheState::Entry
One cached file: identity used for invalidation, plus its pin.

Functions

auto base64_decode(const std::string_view input) -> std::string
Decode a Base64 string.
auto base64_encode(const unsigned char* data, const size_t len) -> std::string
Encode bytes as a Base64 string.
auto is_basic_auth_enabled(const std::string_view auth) -> bool
Whether HTTP Basic authentication is enabled for this auth setting.
auto constant_time_equals(const std::string_view a, const std::string_view b) -> bool
Compare two strings in constant time.
auto apr1_to64(uint32_t value, int count) -> std::string
Encode a value in the Apache APR1 hash alphabet.
auto sha512_base64(const std::string_view password) -> std::string
SHA-512 hash of a password, Base64-encoded.
auto verify_htpasswd_entry(const std::string_view password, std::string_view stored_hash) -> bool
Verify a password against a single htpasswd hash entry.
auto verify_htpasswd_file(const std::string& path, const std::string_view user, const std::string_view password) -> bool
Verify credentials against an htpasswd file.
auto get_mime_type(const std::string& path) -> std::string
Determines the MIME type of the file based on the file extension.
void set_file_ok(const std::string& file_path, std::string content, Response& res)
Fill a successful static-file response.
auto read_file_bytes(const std::string& file_path) -> std::optional<std::string>
Read an entire file as bytes.
auto serve_file(const std::string& file_path, Response& res) -> bool
Read a regular file and prepare an HTTP 200 response.
auto setup_file_handler(const std::vector<std::string>& locations, FileHandler& file_server) -> bool
Registers route:directory pairs on a FileHandler.