I am using warp
to build a Proxy. The proxy doesn't care about parameters or path, it just delegate requests from clients. So the client may query like:
https://proxy.com/p1?a=1&b=2
or
https://proxy.com/p2?c=1
or many other different paths
I want to write something like this:
/*
client query: https://proxy.com/test_path1?a=1
client query: https://proxy.com/test_path2?b=2
*/
let filter = warp::any()
.and(warp::query::<HashMap<String, String>>())
.map(|p: HashMap<String, String>| {
let path = xxx.get_path(); // path = "/test_path1" or "/test_path2"
println!("{:?}",p); // p = {"a":1} or {"b":2} respectively
});
instead of this:
let path1 = warp::path("test_path1").and(warp::query::<HashMap<String, String>>()).map(|p: HashMap<String,String>|{
let path = "test_path1".to_string();
println!("{:?}",p); // p = {"a":1} or {"b":2} respectively
});
let path2 = warp::path("test_path2").and(warp::query::<HashMap<String, String>>()).map(|p: HashMap<String,String>|{
let path = "test_path2".to_string();
println!("{:?}",p); // p = {"a":1} or {"b":2} respectively
});
How can I do it?