Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

axum-extra/scheme: Use rejection macros for SchemeMissing rejection #3113

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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