Unverified Commit ac29014f authored by Mike Seddon's avatar Mike Seddon Committed by GitHub
Browse files

Add tower feature (#159)

parent af31aaeb
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@ rustdoc-args = ["--cfg", "docsrs"]

[features]
openssl = ["dep:openssl"]
tower = ["dep:tower"]

[target.'cfg(not(windows))'.dependencies]
openssl = { version = "0.10.62", optional = true }
@@ -52,6 +53,7 @@ sha2 = "0.10.7"
smallvec = "1.11.0"
thiserror = "1.0.45"
time = { version = "0.3.25", features = ["formatting", "parsing", "macros"] }
tower = { version = "0.4.13", optional = true } 
tracing = "0.1.37"
transform-stream = "0.3.0"
urlencoding = "2.1.3"
+19 −0
Original line number Diff line number Diff line
@@ -124,6 +124,25 @@ impl Service<hyper::Request<hyper::body::Incoming>> for SharedS3Service {
    }
}

#[cfg(feature = "tower")]
impl tower::Service<hyper::Request<hyper::body::Incoming>> for SharedS3Service {
    type Response = hyper::Response<Body>;

    type Error = S3Error;

    type Future = BoxFuture<'static, Result<Self::Response, Self::Error>>;

    fn poll_ready(&mut self, _cx: &mut std::task::Context<'_>) -> std::task::Poll<Result<(), Self::Error>> {
        std::task::Poll::Ready(Ok(()))
    }

    fn call(&mut self, req: hyper::Request<hyper::body::Incoming>) -> Self::Future {
        let req = req.map(Body::from);
        let service = self.0.clone();
        Box::pin(service.call_shared(req))
    }
}

#[derive(Clone)]
pub struct MakeService<S>(S);