From 8e78a37660c0e577765bd7a8fb781f48c56c3ef7 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Fri, 27 Dec 2024 10:01:59 +0100 Subject: [PATCH] axum-extra/scheme: Use rejection macros for `SchemeMissing` rejection (#3113) --- axum-extra/src/extract/scheme.rs | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/axum-extra/src/extract/scheme.rs b/axum-extra/src/extract/scheme.rs index 891d5c0bdd..b20e9cf205 100644 --- a/axum-extra/src/extract/scheme.rs +++ b/axum-extra/src/extract/scheme.rs @@ -1,10 +1,8 @@ //! Extractor that parses the scheme of a request. //! See [`Scheme`] for more details. -use axum::{ - extract::FromRequestParts, - response::{IntoResponse, Response}, -}; +use axum::extract::FromRequestParts; +use axum_core::__define_rejection as define_rejection; use http::{ header::{HeaderMap, FORWARDED}, request::Parts, @@ -23,15 +21,12 @@ const X_FORWARDED_PROTO_HEADER_KEY: &str = "X-Forwarded-Proto"; #[derive(Debug, Clone)] pub struct Scheme(pub String); -/// Rejection type used if the [`Scheme`] extractor is unable to -/// resolve a scheme. -#[derive(Debug)] -pub struct SchemeMissing; - -impl IntoResponse for SchemeMissing { - fn into_response(self) -> Response { - (http::StatusCode::BAD_REQUEST, "No scheme found in request").into_response() - } +define_rejection! { + #[status = BAD_REQUEST] + #[body = "No scheme found in request"] + /// Rejection type used if the [`Scheme`] extractor is unable to + /// resolve a scheme. + pub struct SchemeMissing; } impl FromRequestParts for Scheme