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

Response returns 404 instead of 405 #489

Closed
imor opened this issue Jan 23, 2023 · 0 comments
Closed

Response returns 404 instead of 405 #489

imor opened this issue Jan 23, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@imor
Copy link

imor commented Jan 23, 2023

One of our tests started failing when we upgraded from 1.3.48 to 1.3.52. The test expected that calling a URL with an HTTP method which was not defined for a URL returns status code 405. After the upgrade, status code 404 was returned. I have traced the change in behaviour down to this commit. I also have a minimal example reproducing the problem:

use poem::{listener::TcpListener, Route, Server};
use poem_openapi::{param::Query, payload::PlainText, OpenApi, OpenApiService};

struct Api;

#[OpenApi]
impl Api {
    #[oai(path = "/hello", method = "get")]
    async fn get_hello(&self) -> PlainText<String> {
        PlainText("GET /hello response".to_string())
    }

    #[oai(path = "/hello", method = "delete")]
    async fn delete_hello(&self) -> PlainText<String> {
        PlainText("DELETE /hello response".to_string())
    }

    #[oai(path = "/goodbye", method = "get")]
    async fn get_goodbye(&self) -> PlainText<String> {
        PlainText("GET goodbye response".to_string())
    }
}

#[tokio::main]
async fn main() -> Result<(), std::io::Error> {
    if std::env::var_os("RUST_LOG").is_none() {
        std::env::set_var("RUST_LOG", "poem=debug");
    }
    tracing_subscriber::fmt::init();

    let api_service =
        OpenApiService::new(Api, "Hello World", "1.0").server("http://localhost:3000/api");
    let ui = api_service.swagger_ui();

    Server::new(TcpListener::bind("127.0.0.1:3000"))
        .run(Route::new().nest("/api", api_service).nest("/", ui))
        .await
}

Expected Behavior

Calling DELETE /goodbye should return 405.

Note that if I comment out the delete_hello method, I start getting 405.

Actual Behavior

Calling DELETE /goodbye returns 404.

Steps to Reproduce the Problem

  1. Run the above code snippet.
  2. Call DELETE /goodbye from browser or from any other HTTP client.
  3. Observe that you get a 404 status code instead of a 405.

Specifications

  • Version: 1.3.52
  • Platform: stable-aarch64-apple-darwin
  • Subsystem:
@imor imor added the bug Something isn't working label Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant