pub struct Surf { /* private fields */ }Expand description
Implementationsยง
Sourceยงimpl Surf
impl Surf
Sourcepub fn new(secret: impl Into<String>) -> Self
pub fn new(secret: impl Into<String>) -> Self
Creates a new Surf layer with the provided secret and default token configuration.
Sets the cookie name. Note that this will be previed with __HOST- unless
you have disabled it with prefix. The default value is csrf_token.
Sourcepub fn expires(self, expires: Expiration) -> Self
pub fn expires(self, expires: Expiration) -> Self
Sets the cookieโs expiration. The default value is Expiration::Session.
Sourcepub fn header_name(self, header_name: impl Into<String>) -> Self
pub fn header_name(self, header_name: impl Into<String>) -> Self
Sets the header name used when validating the request. The default
value is X-CSRF-Token.
Sourcepub fn hsts(self, hsts: bool) -> Self
pub fn hsts(self, hsts: bool) -> Self
Sets whether to send the Strict-Transport-Security header.
Sourcepub fn http_only(self, http_only: bool) -> Self
pub fn http_only(self, http_only: bool) -> Self
Sets the HTTPOnly attribute of the cookie. The default value is true.
โ ๏ธ Warning: This should generally not be set to false. See: HttpOnly Cookie Attribute.
Sourcepub fn prefix(self, prefix: bool) -> Self
pub fn prefix(self, prefix: bool) -> Self
Sets whether to prefix the cookie name with __HOST-. The default
value is true.
See: Cookie Name.
Sourcepub fn preload(self, preload: bool) -> Self
pub fn preload(self, preload: bool) -> Self
Sets whether to append the hsts header with preload.
Sourcepub fn same_site(self, same_site: SameSite) -> Self
pub fn same_site(self, same_site: SameSite) -> Self
Sets the SameSite attribute of the cookie. The default value is SameSite::Strict.
Sourcepub fn secure(self, secure: bool) -> Self
pub fn secure(self, secure: bool) -> Self
Sets the secure attribute of the cookie. Note that this is required to
be false for cookies to work on localhost. The default value is true.
See: Secure Cookie Attribute.