Using CorsLayer with axum blocks all http requests OPTIONS method
daltoncoder opened this issue · 1 comments
daltoncoder commented
- [ x] I have looked for existing issues (including closed) about this
Bug Report
Version
tower-http v0.5.2
Platform
Linux 6.9.3-arch1-1
Description
It seems using CorsLayer as a layer on an axum server stops any request with an OPTIONS method from ever hitting handler and responds with a default blank 200 response. Issue happens when using CorsLayer::permissive() and very_permissive(). I once was hitting the issue when manually adding with_methods() but currently can not recreate. Here is minimal snippet of code that will reproduce the bug. If you send any request with OPTIONS method the handler will never get hit.
use axum::{routing::any, Router};
use tower_http::cors::CorsLayer;
#[tokio::main]
async fn main() {
let app = Router::new()
.route("/", any(root))
.layer(CorsLayer::permissive());
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
async fn root() -> String {
println!("in the handler");
"Hello".to_string()
}
jplatte commented
This is intended, not a bug. The middleware handles OPTIONS
requests without calling the inner service. Why do you want to write a custom handler for it?