adding responder
This commit is contained in:
parent
f89c1582f3
commit
f5f3ee67a5
@ -1,5 +1,6 @@
|
||||
mod builder;
|
||||
mod config;
|
||||
mod server;
|
||||
mod responder;
|
||||
|
||||
pub use server::Server;
|
||||
|
15
src/responder.rs
Normal file
15
src/responder.rs
Normal file
@ -0,0 +1,15 @@
|
||||
use http::Response;
|
||||
use http_body_util::Full;
|
||||
use hyper::body::Bytes;
|
||||
use std::convert::Infallible;
|
||||
|
||||
pub struct Responder;
|
||||
|
||||
impl Responder {
|
||||
pub fn unathorized() -> Result<Response<Full<Bytes>>, Infallible> {
|
||||
Ok(Response::builder()
|
||||
.status(401)
|
||||
.body(Full::new(Bytes::from("Unauthorized")))
|
||||
.unwrap())
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
use crate::{builder::ServerBuilder, config::ServerConfig};
|
||||
use crate::{builder::ServerBuilder, config::ServerConfig, responder::Responder};
|
||||
use http1::Builder;
|
||||
use http_body_util::Full;
|
||||
use hyper::{body::Incoming, server::conn::http1, service::service_fn, Request, Response};
|
||||
@ -58,10 +58,7 @@ impl Server {
|
||||
if config.is_req_authorized(&req) {
|
||||
handler(req).await
|
||||
} else {
|
||||
Ok(Response::builder()
|
||||
.status(401)
|
||||
.body(Full::new(Bytes::from("Unauthorized")))
|
||||
.unwrap())
|
||||
Responder::unathorized()
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
Loading…
x
Reference in New Issue
Block a user