diff options
author | Timo Kösters <timo@koesters.xyz> | 2022-10-15 16:56:08 +0200 |
---|---|---|
committer | Timo Kösters <timo@koesters.xyz> | 2022-10-30 19:53:05 +0100 |
commit | 7c98ba64aa3f64be9aff77f36c33d2d48d9653b4 (patch) | |
tree | 0bce90e95d41942a16c59ce71d6bdb1d9e6b68e6 /src/main.rs | |
parent | 2231a69b4c91e4b774975dae653488ab640b6a23 (diff) | |
download | conduit-7c98ba64aa3f64be9aff77f36c33d2d48d9653b4.zip |
fix: HEAD requests should produce METHOD_NOT_ALLOWED
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs index 626de3a..a782de0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,10 +24,13 @@ use figment::{ }; use http::{ header::{self, HeaderName}, - Method, Uri, + Method, StatusCode, Uri, }; use opentelemetry::trace::{FutureExt, Tracer}; -use ruma::api::{client::error::ErrorKind, IncomingRequest}; +use ruma::api::{ + client::{error::Error as RumaError, error::ErrorKind, uiaa::UiaaResponse}, + IncomingRequest, +}; use tokio::signal; use tower::ServiceBuilder; use tower_http::{ @@ -191,15 +194,18 @@ async fn run_server() -> io::Result<()> { async fn unrecognized_method<B>( req: axum::http::Request<B>, next: axum::middleware::Next<B>, -) -> std::result::Result<axum::response::Response, axum::http::StatusCode> { +) -> std::result::Result<axum::response::Response, StatusCode> { let method = req.method().clone(); let uri = req.uri().clone(); let inner = next.run(req).await; if inner.status() == axum::http::StatusCode::METHOD_NOT_ALLOWED { warn!("Method not allowed: {method} {uri}"); - return Ok( - Error::BadRequest(ErrorKind::Unrecognized, "Unrecognized request").into_response(), - ); + return Ok(RumaResponse(UiaaResponse::MatrixError(RumaError { + kind: ErrorKind::Unrecognized, + message: "M_UNRECOGNIZED: Unrecognized request".to_owned(), + status_code: StatusCode::METHOD_NOT_ALLOWED, + })) + .into_response()); } Ok(inner) } |