Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WebServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
codecraft
WebServer
Commits
47cf59bd
Commit
47cf59bd
authored
1 year ago
by
codecraft
Browse files
Options
Downloads
Patches
Plain Diff
Add some documentation
parent
02b28058
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Initial feature merge
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/http/src/handling/response/traits.rs
+1
-1
1 addition, 1 deletion
core/http/src/handling/response/traits.rs
core/http/src/handling/routes.rs
+28
-0
28 additions, 0 deletions
core/http/src/handling/routes.rs
with
29 additions
and
1 deletion
core/http/src/handling/response/traits.rs
+
1
−
1
View file @
47cf59bd
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;
...
...
This diff is collapsed.
Click to expand it.
core/http/src/handling/routes.rs
+
28
−
0
View file @
47cf59bd
...
...
@@ -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
,
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment