diff options
author | Martin Fischer <martin@push-f.com> | 2021-01-18 10:03:50 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-01-18 10:17:10 +0100 |
commit | 9b2d39933f3403245f97247166818bef609a0125 (patch) | |
tree | e5819cf6314e357b7b37e23ae277cd2fea165afc /src/security.rs | |
parent | c27c5b3109e2b4fd8cdbe312f4925edc238a25e9 (diff) |
split Request wrapper into Parts & Bodyv0.2.0
Originally the into_ functions actually consumed the request but I
changed that to make request information like URI and method still
accessible after the request has been read.
Not consuming the Request however allows e.g. into_form() to be called
twice, which results in a panic since the body can only be read once.
This commit splits the Request wrapper into two wrappers Parts & Body,
allowing the borrow checker to guarantee that the body is only consumed
once, while keeping the other request information accessible after the
body has been consumed.
Version bumped to 0.2.0.
Diffstat (limited to 'src/security.rs')
-rw-r--r-- | src/security.rs | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/security.rs b/src/security.rs index fe9c26b..4a17fe3 100644 --- a/src/security.rs +++ b/src/security.rs @@ -6,9 +6,9 @@ use time::{Duration, OffsetDateTime}; pub use crate::signed::Key; -use crate::{Error, Request, Response}; +use crate::{Error, request::Parts, response::Response}; -/// A cookie-based CSRF token to be used with [`crate::Request::into_form_csrf`]. +/// A cookie-based CSRF token to be used with [`crate::request::Body::into_form_csrf`]. pub struct CsrfToken { token: String, from_client: bool, @@ -17,7 +17,7 @@ pub struct CsrfToken { impl CsrfToken { /// Retrieves the CSRF token from a `csrf` cookie or generates /// a new token and stores it as a cookie if it doesn't exist. - pub fn from_request(request: &mut Request, response: &mut Response) -> Self { + pub fn from_parts(request: &mut Parts, response: &mut Response) -> Self { if let Some(cookie) = request.cookies().get("csrf") { return CsrfToken{token: cookie.value().to_string(), from_client: true} } |