diff --git a/core/http/src/handling/response/traits.rs b/core/http/src/handling/response/traits.rs index 700c392a2af59234b0154b5c14241f75a010ee33..bc0aed55e9beba1ebbc2e74081d577588b71135b 100644 --- a/core/http/src/handling/response/traits.rs +++ b/core/http/src/handling/response/traits.rs @@ -1,7 +1,7 @@ use crate::{handling::routes::Body, utils::mime::Mime}; pub trait ResponseBody: Send { - /// Get a cloned version of the data as a [Vec<u8>] + /// Get a cloned version of the data as a [`Vec<u8>`] /// # Ecamples /// ``` /// use http::handling::response::ResponseBody; diff --git a/core/http/src/handling/routes.rs b/core/http/src/handling/routes.rs index e4246b8992407281c9a555b509115f149f4fb9a4..a31dc80b5162a3f607b874e0bbabf4b314659d80 100644 --- a/core/http/src/handling/routes.rs +++ b/core/http/src/handling/routes.rs @@ -16,13 +16,34 @@ pub struct RoutInfo { rank: Option<isize>, } +/// A struct to define Routes on the Server #[derive(Clone, Copy)] pub struct Route<'a> { + /// An optional name of the route pub name: Option<&'static str>, + /// The [Method] via which the route is accesable pub method: Method, + /// The Uri of the route, allows special cases: + /// # Examples + /// ``` + /// "/home"; // Only /home + /// "/<home>/something"; + /// // Variable content the users provides this acts for /<anything>/something + /// "/<home..>"; + /// // All Information after this sequence is irrelvent + /// // Matches: /a, /a/b/c ... + /// ``` pub uri: Uri<'a>, + /// The Handler function for this route, which gets called when the request need the route. + /// Inputs to the function are an [Request] and the [Data] which represents the body of the + /// [Request]. The Outcome is expected to be an [Outcome], which is a [Response], A [Status] if + /// something went wrong and a [Status] page is need or a [Outcome::Forward] of the requests + /// [Data] for the next [Route] to take care of. pub handler: fn(Request, Data) -> Outcome<Response, Status, Data>, + /// The Rank of the Route, dependent on its specificness. so the rank of a uri `"/home"` would be + /// ranked high, whereas a uri of `"/<anything..>"` would be ranked the lowest pub rank: isize, + /// The Specific answer format of the [Route] as a [MediaType]. Optional pub format: Option<MediaType>, } @@ -38,6 +59,7 @@ impl Route<'_> { format: routeinfo.format, } } + /// Matches a [Request] Uri with a [Route] Uri. Respecting special cases like `?` and `<a..>` pub fn compare_uri(&self, uri: Uri) -> bool { let mut iter_comp_str = uri.split('/'); for true_str in self.uri.split('/') { @@ -65,8 +87,11 @@ impl Route<'_> { pub type Uri<'a> = &'a str; #[derive(Debug, Clone)] +/// A basic Body type for respones pub struct Body { + /// The Response body body: Vec<u8>, + /// The Mime Type mime_type: Mime, } @@ -89,8 +114,11 @@ impl Body { } #[derive(Debug, Clone)] +/// Data of the Body of a [Request] pub struct Data { + /// The Data pub buffer: Vec<u8>, + /// For Split Data if it is complete pub is_complete: bool, }