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

Add Ranking

parent a9ee87ff
No related branches found
No related tags found
No related merge requests found
use std::{fmt::Display, str::FromStr};
#[derive(PartialEq, Eq, Clone, Debug, Copy)]
#[derive(PartialEq, Eq, Clone, Debug, Copy, PartialOrd, Ord)]
pub enum Method {
Get,
Head,
......
use std::net::SocketAddr;
// use std::net::SocketAddr;
use super::{methods::Method, routes::Uri};
......@@ -11,12 +11,12 @@ pub struct Request<'a> {
// pub connection: ConnectionMeta,
}
struct ConnectionMeta {
remote: Option<SocketAddr>,
// certificates
}
// struct ConnectionMeta {
// remote: Option<SocketAddr>,
// // certificates
// }
#[derive(Clone, Debug, Copy)]
#[derive(Clone, Debug, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum MediaType {
Json,
Plain,
......
use std::{
thread::available_parallelism, process::exit,
};
use std::thread::available_parallelism;
use tokio::{net::TcpListener, signal::unix::{SignalKind, signal}, runtime, select};
use tokio::{net::TcpListener, signal::unix::{SignalKind, signal}, select};
use crate::{
handlers::handlers::handle_connection,
......@@ -21,7 +19,8 @@ pub struct Config {
}
impl<'a> Config {
pub fn mount(mut self, mountpoint: Uri<'static>, routes: Vec<Route<'static>>) -> Config {
pub fn mount(mut self, mountpoint: Uri<'static>, mut routes: Vec<Route<'static>>) -> Config {
routes.sort_by(|a, b| a.rank.cmp(&b.rank));
let mut mount_message = format!(" >> \x1b[35m{}\x1b[0m\n", mountpoint);
for (index, route) in routes.iter().enumerate() {
let indent_sign;
......
......@@ -8,6 +8,15 @@ use http::handling::{
routes::{Data, Route},
};
fn handle_static_hi(request: Request<'_>, data: Data) -> Outcome<Response, Status, Data> {
// Outcome::Success(Response { headers: vec![
// format!("Content-Length: 4"),
// format!("Content-Type: text/plain")
// ], status: Some(Status::Ok), body: Box::new("jkl;") })
Outcome::Forward(data)
}
fn handler(request: Request<'_>, _data: Data) -> Outcome<Response, Status, Data> {
let response = fileserver(request.uri.strip_prefix("static/").unwrap());
let response = match response {
......@@ -60,7 +69,7 @@ async fn main() {
name: Some("file_server"),
uri: "static/<path..>",
method: Method::Get,
rank: 0,
rank: 1,
};
let post_test = Route {
......@@ -72,7 +81,16 @@ async fn main() {
rank: 0,
};
let static_hi = Route {
format: None,
handler: handle_static_hi,
name: Some("Handle_Static_hi"),
uri: "static/hi",
method: Method::Get,
rank: 0
};
http::build("127.0.0.1:8000").await
.mount("/", vec![fileserver, post_test])
.mount("/", vec![fileserver, post_test, static_hi])
.launch().await;
}
asdf
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