From: Martin Pitt Date: Tue, 1 Nov 2022 15:30:53 +0000 (+0100) Subject: warp-server: Add User-Agent header filter X-Git-Url: https://piware.de/gitweb/?a=commitdiff_plain;h=b2728f732e28cdd993c35870bf8cd5369f43a801;p=learn-rust.git warp-server: Add User-Agent header filter --- diff --git a/warp-server/src/main.rs b/warp-server/src/main.rs index 70b3cc3..a89c7a6 100644 --- a/warp-server/src/main.rs +++ b/warp-server/src/main.rs @@ -4,7 +4,8 @@ use warp::Filter; async fn main() { // GET /hello/warp => 200 OK with body "Hello, warp!" let hello = warp::path!("hello" / String) - .map(|name| format!("Hello, {}!", name)); + .and(warp::header::("user-agent")) + .map(|name, agent| format!("Hello, {} from {}!", name, agent)); warp::serve(hello) .run(([127, 0, 0, 1], 3030))