Serving a path in directory in Warp not working

I have the warp code:

fn get_persistent_video(
    downloads_path: PathBuf,
) -> impl Filter<Extract = (impl warp::Reply,), Error = warp::Rejection> + Clone {
    let path = downloads_path.join("5001");

    warp::path!("api" / "persistent-videos").and(warp::fs::dir(path))
}

and expect to be served the file test.mp4 when calling:

curl -ikX GET "https://0.0.0.0:3030/api/persistent-videos/test.mp4"

But I get the internal server log message:

14:39:16 [DEBUG] (6) warp::filter::service: rejected: Rejection(NotFound)

which causes a 404 on the client end.
Note that the downloads_path is absolute (e.g. here it is usually /workspace/downloads/5001/test.mp4), not relative to the current directory. Is that an issue?
Any ideas?

I'd assume it tries to serve /workspace/downloads/5001/test.mp4 from your computer. If you want to serve $PWD/workspace/downloads/5001/test.mp4, I'd remove the leading slash and try again.

I specifically want to serve /workspace/downloads/5001/test.mp4 though, and that doesn't seem to work.

Maybe someone can try:

#[tokio::main]
async fn main() -> Result<()> {
    let route =
        warp::path!("api" / "persistent-videos").and(warp::fs::dir("/workspace/downloads/5001"));

    warp::serve(route).run(([0, 0, 0, 0], 3030)).await;

on their machine, and place a file that is then requested in /workspace/downloads/5001.
I just tested just that on my device and still get a 404 not found.
I'm very confused why this isn't working.
Any help would be appreciated!

I have the same problem on my machine.

I think the problem is the warp::path! macro. Especially this section seems relevant, though I don't know what end() does in warp-land. But if I change your route to this:

let route = warp::path!("api" / "persistent-videos" / ..).and(warp::fs::dir("/tmp"));

or

let route = warp::path("api")
    .and(warp::path("persistent-videos"))
    .and(warp::fs::dir("/tmp"));

it serves my test file properly.

1 Like