mirror of
https://github.com/element-hq/matrix-authentication-service.git
synced 2026-05-16 14:25:25 +00:00
Rework warp top-filters to get proper 404 errors
Before, some had `warp::get().and(warp::path!("foo"))`, which resulted
to a `405 Method not allowed` instead of a 404.
It also uses the `wrap::path!` macro instead of the function to ensure
we're not setting a prefix
This commit is contained in:
@@ -23,8 +23,8 @@ use crate::{errors::WrapError, filters::database::with_connection};
|
||||
pub fn filter(
|
||||
pool: &PgPool,
|
||||
) -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone + Send + Sync + 'static {
|
||||
warp::get()
|
||||
.and(warp::path("health"))
|
||||
warp::path!("health")
|
||||
.and(warp::get())
|
||||
.and(with_connection(pool))
|
||||
.and_then(get)
|
||||
}
|
||||
|
||||
@@ -163,8 +163,8 @@ pub fn filter(
|
||||
cookies_config: &CookiesConfig,
|
||||
) -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone + Send + Sync + 'static {
|
||||
let clients = oauth2_config.clients.clone();
|
||||
let authorize = warp::get()
|
||||
.and(warp::path!("oauth2" / "authorize"))
|
||||
let authorize = warp::path!("oauth2" / "authorize")
|
||||
.and(warp::get())
|
||||
.map(move || clients.clone())
|
||||
.and(warp::query())
|
||||
.and(with_optional_session(pool, cookies_config))
|
||||
@@ -172,8 +172,8 @@ pub fn filter(
|
||||
.and(with_templates(templates))
|
||||
.and_then(get);
|
||||
|
||||
let step = warp::get()
|
||||
.and(warp::path!("oauth2" / "authorize" / "step"))
|
||||
let step = warp::path!("oauth2" / "authorize" / "step")
|
||||
.and(warp::get())
|
||||
.and(warp::query().map(|s: StepRequest| s.id))
|
||||
.and(with_session(pool, cookies_config))
|
||||
.and(with_transaction(pool))
|
||||
|
||||
@@ -60,8 +60,8 @@ pub(super) fn filter(
|
||||
|
||||
let cors = warp::cors().allow_any_origin();
|
||||
|
||||
warp::get()
|
||||
.and(warp::path!(".well-known" / "openid-configuration"))
|
||||
warp::path!(".well-known" / "openid-configuration")
|
||||
.and(warp::get())
|
||||
.map(move || warp::reply::json(&metadata))
|
||||
.with(cors)
|
||||
}
|
||||
|
||||
@@ -32,8 +32,8 @@ pub(super) fn filter(
|
||||
csrf_config: &CsrfConfig,
|
||||
cookies_config: &CookiesConfig,
|
||||
) -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone + Send + Sync + 'static {
|
||||
warp::get()
|
||||
.and(warp::path::end())
|
||||
warp::path::end()
|
||||
.and(warp::get())
|
||||
.and(with_templates(templates))
|
||||
.and(updated_csrf_token(cookies_config, csrf_config))
|
||||
.and(with_optional_session(pool, cookies_config))
|
||||
|
||||
@@ -99,7 +99,7 @@ pub(super) fn filter(
|
||||
.untuple_one()
|
||||
.with(wrap_fn(save_session(cookies_config)));
|
||||
|
||||
warp::path("login").and(get.or(post))
|
||||
warp::path!("login").and(get.or(post))
|
||||
}
|
||||
|
||||
async fn get(
|
||||
|
||||
@@ -26,8 +26,8 @@ pub(super) fn filter(
|
||||
pool: &PgPool,
|
||||
cookies_config: &CookiesConfig,
|
||||
) -> impl Filter<Extract = (impl Reply,), Error = Rejection> + Clone + Send + Sync + 'static {
|
||||
warp::post()
|
||||
.and(warp::path("logout"))
|
||||
warp::path!("logout")
|
||||
.and(warp::post())
|
||||
.and(with_session(pool, cookies_config))
|
||||
.and(with_connection(pool))
|
||||
.and(protected_form(cookies_config))
|
||||
|
||||
@@ -54,7 +54,7 @@ pub(super) fn filter(
|
||||
.and(protected_form(cookies_config))
|
||||
.and_then(post);
|
||||
|
||||
warp::path("reauth").and(get.or(post))
|
||||
warp::path!("reauth").and(get.or(post))
|
||||
}
|
||||
|
||||
async fn get(
|
||||
|
||||
Reference in New Issue
Block a user