diff --git a/core/http/src/handling/request/datatypes.rs b/core/http/src/handling/request/datatypes.rs index 6d37b1f6ffc5a0d05e553ed178aa17f1650914b2..e8b03030d171a5a089f1dcd02f4106b6bbc1e72e 100644 --- a/core/http/src/handling/request/datatypes.rs +++ b/core/http/src/handling/request/datatypes.rs @@ -1,7 +1,7 @@ use std::{collections::HashMap, error::Error, fmt::Display}; use crate::{ - handling::{methods::Method, routes::Uri}, + handling::methods::Method, utils::{mime::Mime, urlencoded::UrlEncodeData}, }; diff --git a/core/http/src/handling/request/form_utils.rs b/core/http/src/handling/request/form_utils.rs index b1e3a761cb5749ff150a3490baacb8b6a9011aaa..7991f4d2febcbbb38d8066a6d5f0be87a9e14790 100644 --- a/core/http/src/handling/request/form_utils.rs +++ b/core/http/src/handling/request/form_utils.rs @@ -20,14 +20,12 @@ impl Request { /// /// # Examples /// ``` - /// use http::handling::request::Request; - /// use http::handling::request::ParseFormError; - /// use http::handling::request::ParseErrors; - /// use http::handling::methods::Method; + /// use http::handling::{request::{Request, ParseFormError, ParseErrors}, methods::Method}; + /// use http::utils::urlencoded::UrlEncodeData; /// /// /// let request = Request { - /// uri: "/form?name=Name&age=Age", + /// uri: UrlEncodeData::from_encoded("/form?name=Name&age=Age").unwrap(), /// headers: vec![], /// method: Method::Get, /// cookies: None, @@ -38,7 +36,7 @@ impl Request { /// assert_eq!(&"Age", right.get("age").unwrap().as_ref().unwrap()); /// /// let wrong_request = Request { - /// uri: "/form", + /// uri: UrlEncodeData::from_encoded("/form").unwrap(), /// ..request.clone() /// }; /// assert_eq!( @@ -49,7 +47,7 @@ impl Request { /// ); /// /// let bad_data = Request { - /// uri: "/form?age=", + /// uri: UrlEncodeData::from_encoded("/form?age=").unwrap(), /// ..request.clone() /// }; /// let wrong = bad_data.get_get_form_keys(&["name", "age"]).unwrap(); diff --git a/core/http/src/handling/request/request_mime.rs b/core/http/src/handling/request/request_mime.rs index c37045e7af53712e33572e41629516b6840d8e72..75ad1e547677443479764d6b94013aacd57156ec 100644 --- a/core/http/src/handling/request/request_mime.rs +++ b/core/http/src/handling/request/request_mime.rs @@ -9,11 +9,11 @@ impl Request { /// ``` /// use http::{ /// handling::{methods::Method, request::Request}, - /// utils::mime::Mime, + /// utils::{mime::Mime, urlencoded::UrlEncodeData}, /// }; /// /// let mut request = Request { - /// uri: "thing", + /// uri: UrlEncodeData::from_encoded("thing").unwrap(), /// headers: vec![ /// "GET / 23".to_string(), /// "SDF:LKJSD:F".to_string(), @@ -25,7 +25,7 @@ impl Request { /// mime_type: None, /// }; /// let mut wrong = Request { - /// uri: "thing", + /// uri: UrlEncodeData::from_encoded("thing").unwrap(), /// headers: vec![ /// "GET / 23".to_string(), /// "SDF:LKJSD:F".to_string(), diff --git a/core/http/src/handling/response/traits.rs b/core/http/src/handling/response/traits.rs index fc7eb094af30fe3b59b75eb8c89791af463acdfc..700c392a2af59234b0154b5c14241f75a010ee33 100644 --- a/core/http/src/handling/response/traits.rs +++ b/core/http/src/handling/response/traits.rs @@ -1,8 +1,30 @@ use crate::{handling::routes::Body, utils::mime::Mime}; pub trait ResponseBody: Send { + /// Get a cloned version of the data as a [Vec<u8>] + /// # Ecamples + /// ``` + /// use http::handling::response::ResponseBody; + /// let data = "DATA"; + /// assert_eq!(b"DATA".to_vec(), data.get_data()); + /// ``` fn get_data(&self) -> Vec<u8>; + /// get the miem type of the data as a [Mime] + /// # Examples + /// ``` + /// use http::handling::response::ResponseBody; + /// use http::utils::mime::Mime; + /// let data = "DATA"; + /// assert_eq!(Mime::TextPlain, data.get_mime()); + /// ``` fn get_mime(&self) -> Mime; + /// get the length in bytes of the data as a [usize] + /// # Examples + /// ``` + /// use http::handling::response::ResponseBody; + /// let data = "DATA"; + /// assert_eq!(4, data.get_len()); + /// ``` fn get_len(&self) -> usize; }