feat: new matcher system instead of manually 'match'ing in servcie
This commit is contained in:
parent
f305cb5a85
commit
638b0376d8
15 changed files with 646 additions and 225 deletions
|
@ -2,9 +2,13 @@ use std::{any::type_name_of_val, error::Error};
|
|||
|
||||
use http_body_util::{Either, Full};
|
||||
use hyper::{
|
||||
body::{Body, Bytes, Incoming}, server::conn::http1, service::{HttpService, Service}, Request, Response, StatusCode
|
||||
Request, Response, StatusCode,
|
||||
body::{Body, Bytes, Incoming},
|
||||
server::conn::http1,
|
||||
service::{HttpService, Service},
|
||||
};
|
||||
use hyper_util::rt::TokioIo;
|
||||
use json::JsonValue;
|
||||
use log::{error, info};
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
|
||||
|
@ -34,13 +38,25 @@ pub async fn default_response() -> GeneralResponse {
|
|||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn custom_resp(e: StatusCode, m: &'static str) -> GeneralResponse {
|
||||
pub async fn custom_resp(e: StatusCode, m: String) -> GeneralResponse {
|
||||
Response::builder()
|
||||
.status(e)
|
||||
.body(GeneralBody::Right(Full::from(Bytes::from(m))))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub async fn json_to_vec(v: JsonValue) -> Option<Vec<String>> {
|
||||
if let JsonValue::Array(arr) = v {
|
||||
Some(
|
||||
arr.into_iter()
|
||||
.map(|val| val.as_str().unwrap().to_string())
|
||||
.collect(),
|
||||
)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
impl<S> Server<S>
|
||||
where
|
||||
S: TcpIntercept,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue