23 Csrf(
const std::string& cookie_name =
"csrf_token",
const std::string& header_name =
"X-CSRF-Token");
43 std::string cookie_name_;
44 std::string header_name_;
55inline auto csrf_protection(
const std::string& cookie_name =
"csrf_token",
const std::string& header_name =
"X-CSRF-Token") {
56 return [c = std::make_shared<Csrf>(cookie_name, header_name)](
http::HttpRequest& req, std::shared_ptr<http::ResponseWriter> writer) ->
bool {
57 return (*c)(req, writer);
Cross-Site Request Forgery (CSRF) protection middleware.
Definition Csrf.hpp:15
static std::string generate_random_token()
Generates a random CSRF token.
Definition Csrf.cpp:10
bool operator()(http::HttpRequest &req, std::shared_ptr< http::ResponseWriter > writer)
Middleware execution operator.
Definition Csrf.cpp:26
auto csrf_protection(const std::string &cookie_name="csrf_token", const std::string &header_name="X-CSRF-Token")
Helper to create a CSRF protection middleware handler.
Definition Csrf.hpp:55
Definition Compress.hpp:4
Represents an incoming HTTP request.
Definition HttpRequest.hpp:22