| 44 | } |
| 45 | |
| 46 | fn call(&mut self, _req: Request<Full<Bytes>>) -> Self::Future { |
| 47 | let count = self |
| 48 | .request_count |
| 49 | .fetch_add(1, std::sync::atomic::Ordering::SeqCst); |
| 50 | |
| 51 | Box::pin(async move { |
| 52 | // Simulate network delay for first request |
| 53 | if count == 0 { |
| 54 | tokio::time::sleep(std::time::Duration::from_millis(200)).await; |
| 55 | } |
| 56 | |
| 57 | let response_body = |
| 58 | format!("Response #{} with caching enabled", count + 1); |
| 59 | |
| 60 | Ok(http::Response::builder() |
| 61 | .status(StatusCode::OK) |
| 62 | .header("cache-control", "max-age=300, public") |
| 63 | .header("content-type", "text/plain") |
| 64 | .body(Full::new(Bytes::from(response_body)))?) |
| 65 | }) |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | #[tokio::main] |