]> piware.de Git - learn-rust.git/blobdiff - warp-server/src/main.rs
warp-server: Add User-Agent header filter
[learn-rust.git] / warp-server / src / main.rs
index 70b3cc3f516dbf3bfb622a7f2231435682b0d609..a89c7a6fd205e4703d04ed7f38a9232799dbd69a 100644 (file)
@@ -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::<String>("user-agent"))
+        .map(|name, agent| format!("Hello, {} from {}!", name, agent));
 
     warp::serve(hello)
         .run(([127, 0, 0, 1], 3030))