diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/request.rs | 4 | ||||
-rw-r--r-- | src/response.rs | 6 | ||||
-rw-r--r-- | src/security.rs | 2 |
3 files changed, 9 insertions, 3 deletions
diff --git a/src/request.rs b/src/request.rs index 195e601..d89248c 100644 --- a/src/request.rs +++ b/src/request.rs @@ -13,6 +13,7 @@ use crate::response::{SputnikHeaders, delete_cookie}; const CSRF_COOKIE_NAME : &str = "csrf"; +/// Adds convenience methods to [`http::request::Parts`](Parts). pub trait SputnikParts { /// Parses the query string of the request into a given struct. fn query<X: DeserializeOwned>(&self) -> Result<X,QueryError>; @@ -32,7 +33,7 @@ pub trait SputnikParts { fn response_headers(&mut self) -> &mut HeaderMap; } -impl SputnikParts for hyper::http::request::Parts { +impl SputnikParts for Parts { fn query<T: DeserializeOwned>(&self) -> Result<T,QueryError> { serde_urlencoded::from_str::<T>(self.uri.query().unwrap_or("")).map_err(QueryError) } @@ -185,6 +186,7 @@ impl CsrfToken { } } +/// Adds deserialization methods to [`hyper::Body`]. #[async_trait] pub trait SputnikBody { async fn into_bytes(self) -> Result<Bytes, BodyError>; diff --git a/src/response.rs b/src/response.rs index c8ff23a..2d5d469 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,4 +1,4 @@ -//! Provides the [`SputnikBuilder`] trait. +//! Provides convenience traits and functions to build HTTP responses. use std::convert::TryInto; @@ -7,6 +7,7 @@ use hyper::{HeaderMap, StatusCode, header, http}; use time::{Duration, OffsetDateTime}; use hyper::http::response::Builder; +/// Adds convenience methods to [`Builder`]. pub trait SputnikBuilder { /// Sets the Content-Type. fn content_type(self, mime: mime::Mime) -> Builder; @@ -15,6 +16,7 @@ pub trait SputnikBuilder { fn set_cookie(self, cookie: Cookie) -> Builder; } +/// Creates a new builder with a given Location header and status code. pub fn redirect(location: &str, code: StatusCode) -> Builder { Builder::new().status(code).header(header::LOCATION, location) } @@ -39,6 +41,7 @@ pub fn delete_cookie(name: &str) -> Cookie { cookie } +/// Adds convenience methods to [`HeaderMap`]. pub trait SputnikHeaders { /// Sets the Content-Type. fn content_type(&mut self, mime: mime::Mime); @@ -57,6 +60,7 @@ impl SputnikHeaders for HeaderMap { } } +/// Adds a convenience method to consume a [`Builder`] with an empty body. pub trait EmptyBuilder<B> { /// Consume the builder with an empty body. fn empty(self) -> http::Result<http::response::Response<B>>; diff --git a/src/security.rs b/src/security.rs index 0ffa7a0..258d3dc 100644 --- a/src/security.rs +++ b/src/security.rs @@ -1,4 +1,4 @@ -//! [`Key`] and functions to encode & decode expiring claims. +//! Provides [`Key`] and functions to encode & decode expiring claims. use time::OffsetDateTime; |