Skip to content
Snippets Groups Projects
Commit 02b28058 authored by codecraft's avatar codecraft :crocodile:
Browse files

Add Doc for ResponseBody trait end correct Doc for request_cookies and

request_form_utils
parent 35c2138d
No related branches found
No related tags found
1 merge request!1Initial feature merge
use std::{collections::HashMap, error::Error, fmt::Display};
use crate::{
handling::{methods::Method, routes::Uri},
handling::methods::Method,
utils::{mime::Mime, urlencoded::UrlEncodeData},
};
......
......@@ -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();
......
......@@ -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(),
......
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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment