24 Csrf(
const std::string& cookie_name =
"csrf_token",
const std::string& header_name =
"X-CSRF-Token");
56inline auto csrf_protection(
const std::string& cookie_name =
"csrf_token",
const std::string& header_name =
"X-CSRF-Token") {
57 return [c = std::make_shared<Csrf>(cookie_name, header_name)](
http::HttpRequest& req, std::shared_ptr<http::ResponseWriter> writer) ->
bool {
58 return (*c)(req, writer);
Cross-Site Request Forgery (CSRF) protection middleware.
Definition Csrf.hpp:16
static std::string generate_random_token()
Generates a random CSRF token.
bool operator()(http::HttpRequest &req, std::shared_ptr< http::ResponseWriter > writer)
Middleware execution operator.
std::string cookie_name_
Definition Csrf.hpp:44
Csrf(const std::string &cookie_name="csrf_token", const std::string &header_name="X-CSRF-Token")
Constructs a new Csrf middleware instance.
std::string header_name_
Definition Csrf.hpp:45
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:56
Definition HttpRequest.hpp:19
Represents an incoming HTTP request.
Definition HttpRequest.hpp:54