diff options
author | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-06-02 16:29:16 +0200 |
---|---|---|
committer | Quentin Dufour <quentin@deuxfleurs.fr> | 2022-06-02 16:29:16 +0200 |
commit | 2d1e6bfffbe0579397b4a045acc5014afc508f65 (patch) | |
tree | 178875d178510c7a278bb0723fe4d53cec7b1ac8 /src/server.rs | |
parent | 109337b904ce1ca03f2f6e6216edc8c1af359870 (diff) | |
download | aerogramme-2d1e6bfffbe0579397b4a045acc5014afc508f65.tar.gz aerogramme-2d1e6bfffbe0579397b4a045acc5014afc508f65.zip |
Working integration v1
Diffstat (limited to 'src/server.rs')
-rw-r--r-- | src/server.rs | 37 |
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?; |