Function warp::filters::path::tail

source · []
pub fn tail() -> impl Filter<Extract = (Tail,), Error = Infallible> + Copy
Expand description

Extract the unmatched tail of the path.

This will return a Tail, which allows access to the rest of the path that previous filters have not already matched.

Example

use warp::Filter;

let route = warp::path("foo")
    .and(warp::path::tail())
    .map(|tail| {
        // GET /foo/bar/baz would return "bar/baz".
        format!("The tail after foo is {:?}", tail)
    });
Examples found in repository?
src/filters/fs.rs (line 92)
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
fn path_from_tail(
    base: Arc<PathBuf>,
) -> impl FilterClone<Extract = One<ArcPath>, Error = Rejection> {
    crate::path::tail().and_then(move |tail: crate::path::Tail| {
        future::ready(sanitize_path(base.as_ref(), tail.as_str())).and_then(|mut buf| async {
            let is_dir = tokio::fs::metadata(buf.clone())
                .await
                .map(|m| m.is_dir())
                .unwrap_or(false);

            if is_dir {
                tracing::debug!("dir: appending index.html to directory path");
                buf.push("index.html");
            }
            tracing::trace!("dir: {:?}", buf);
            Ok(ArcPath(Arc::new(buf)))
        })
    })
}