Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ServeDir::try_call does not propagate result as documented #412

Open
Pistonight opened this issue Sep 23, 2023 · 1 comment
Open

ServeDir::try_call does not propagate result as documented #412

Pistonight opened this issue Sep 23, 2023 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@Pistonight
Copy link

Bug Report

Version

tower-http v0.4.4

Platform

All

Description

When using ServeDir::try_call to request a path that does not exist, it returns Ok(404) instead of an Err

use axum::http::Request;
use tower_http::services::ServeDir;
use tracing::{error, info};

#[tokio::main]
async fn main() {
    tracing_subscriber::fmt::init();

    let mut serve_dir = ServeDir::new("src");

    let mut req = Request::new(());
    *req.uri_mut() = "/main.rs".parse().unwrap();
    match serve_dir.try_call(req).await {
        Ok(response) => info!("response code: {}", response.status()),
        Err(e) => error!("error: {}", e),
    }

    let mut req2 = Request::new(());
    *req2.uri_mut() = "/doesnotexist.rs".parse().unwrap();
    match serve_dir.try_call(req2).await {
        Ok(response) => info!("response code: {}", response.status()),
        Err(e) => error!("error: {}", e),
    }
}

Expected:

2023-09-23T18:09:09.141584Z  INFO rs_playground: response code: 200 OK
2023-09-23T18:09:09.141801Z  ERROR rs_playground: error: <something>

Actual:

2023-09-23T18:09:09.141584Z  INFO rs_playground: response code: 200 OK
2023-09-23T18:09:09.141801Z  INFO rs_playground: response code: 404 Not Found
@jplatte jplatte added the C-bug Category: This is a bug. label Nov 8, 2023
@jplatte
Copy link
Collaborator

jplatte commented Nov 8, 2023

I think a PR to fix this would be welcome (cc @davidpdrsn).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants