addCsrf
mach::AppBuilder::addCsrf
Adds CSRF protection.
Description
Section titled “Description”Adds CSRF protection to the application.
Syntax
Section titled “Syntax”// (1)AppBuilder& addCsrf();
// (2)template <typename TConfigure> requires std::invocable<TConfigure, CsrfBuilder&>AppBuilder& addCsrf(TConfigure&& configure);Return Value
Section titled “Return Value”A reference to the current AppBuilder instance.
Template Parameters
Section titled “Template Parameters”Overload (2)
Section titled “Overload (2)”| Parameter | Description |
|---|---|
TConfigure |
The type of the callable used to configure CSRF. |
Parameters
Section titled “Parameters”Overload (2)
Section titled “Overload (2)”| Parameter | Description |
|---|---|
configure |
A callable that receives a CsrfBuilder used to configure CSRF. |
Remarks
Section titled “Remarks”- In overload (2), the configuration callable is invoked immediately and receives a
CsrfBuilderby reference. - Changes made after
App::run()has been called do not take effect.
Thread Safety
Section titled “Thread Safety”This method is not thread-safe and should only be called during application configuration, before the application starts handling requests.
Examples
Section titled “Examples”Overload (1)
Section titled “Overload (1)”builder.addCsrf();Overload (2)
Section titled “Overload (2)”builder.addCsrf([](mach::CsrfBuilder& csrf) { csrf.cookieName("csrf-token") .headerName("X-CSRF-Token");});See Also
Section titled “See Also”| Name | Description |
|---|---|
CsrfBuilder |
Configures CSRF. |