aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server.rs37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/server.rs b/src/server.rs
index 0fca3ec..46f1f76 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -12,6 +12,13 @@ use boitalettres::server::accept::addr::{AddrIncoming, AddrStream};
use boitalettres::server::Server as ImapServer;
use tracing_subscriber;
+use std::task::{Context, Poll};
+use tower::Service;
+use std::future::Future;
+use std::pin::Pin;
+
+use std::error::Error;
+
pub struct Server {
pub login_provider: Box<dyn LoginProvider>,
}
@@ -21,6 +28,29 @@ async fn handle_req(req: Request) -> Result<Response> {
Ok(Response::ok("Done")?)
}
+struct Echo;
+
+impl Service<Request> for Echo {
+ type Response = Response;
+ type Error = Box<dyn Error + Send + Sync>;
+ type Future = Pin<Box<dyn futures::Future<Output = Result<Self::Response, Self::Error>> + Send>>;
+
+ fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
+ Poll::Ready(Ok(()))
+ }
+
+ fn call(&mut self, req: Request) -> Self::Future {
+ Box::pin(Echo::handle_req(req))
+ }
+}
+
+impl Echo {
+ async fn handle_req(req: Request) -> Result<Response, Box<dyn Error + Send + Sync>> {
+ println!("Got request: {:#?}", req);
+ Ok(Response::ok("Done").unwrap())
+ }
+}
+
impl Server {
pub fn new(config: Config) -> Result<Arc<Self>> {
let s3_region = Region::Custom {
@@ -46,13 +76,18 @@ impl Server {
let incoming = AddrIncoming::new("127.0.0.1:4567").await?;
+
let make_service = tower::service_fn(|addr: &AddrStream| {
tracing::debug!(remote_addr = %addr.remote_addr, local_addr = %addr.local_addr, "accept");
- let service = tower::ServiceBuilder::new().service_fn(handle_req);
+ //let service = tower::ServiceBuilder::new().service_fn(handle_req);
+ //let service = tower::service_fn(handle_req);
+ let service = Echo;
futures::future::ok::<_, std::convert::Infallible>(service)
+ //service
});
+ //println!("{:?}", make_service);
let server = ImapServer::new(incoming).serve(make_service);
let _ = server.await?;