llm_edge_proxy/middleware/
timeout.rs1use std::time::Duration;
4use tower::timeout::TimeoutLayer as TowerTimeoutLayer;
5use tower::Layer;
6use tracing::debug;
7
8#[derive(Clone)]
10pub struct TimeoutLayer {
11 inner: TowerTimeoutLayer,
12}
13
14impl TimeoutLayer {
15 pub fn new(duration: Duration) -> Self {
17 debug!(
18 timeout_secs = duration.as_secs(),
19 "Configuring request timeout"
20 );
21 Self {
22 inner: TowerTimeoutLayer::new(duration),
23 }
24 }
25}
26
27impl<S> Layer<S> for TimeoutLayer {
28 type Service = <TowerTimeoutLayer as Layer<S>>::Service;
29
30 fn layer(&self, service: S) -> Self::Service {
31 self.inner.layer(service)
32 }
33}
34
35#[cfg(test)]
36mod tests {
37 use super::*;
38
39 #[test]
40 fn test_timeout_layer_creation() {
41 let duration = Duration::from_secs(30);
42 let _layer = TimeoutLayer::new(duration);
43 }
45}