From 2d1e6bfffbe0579397b4a045acc5014afc508f65 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 2 Jun 2022 16:29:16 +0200 Subject: Working integration v1 --- src/server.rs | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/server.rs') 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, } @@ -21,6 +28,29 @@ async fn handle_req(req: Request) -> Result { Ok(Response::ok("Done")?) } +struct Echo; + +impl Service for Echo { + type Response = Response; + type Error = Box; + type Future = Pin> + Send>>; + + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { + 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> { + println!("Got request: {:#?}", req); + Ok(Response::ok("Done").unwrap()) + } +} + impl Server { pub fn new(config: Config) -> Result> { 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?; -- cgit v1.2.3