Skip to content

Commit

Permalink
axum-extra/scheme: Use rejection macros for SchemeMissing rejection (
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 authored Dec 27, 2024
1 parent 8def678 commit 8e78a37
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions axum-extra/src/extract/scheme.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<S> FromRequestParts<S> for Scheme
Expand Down

0 comments on commit 8e78a37

Please sign in to comment.