mirror of
https://github.com/tokio-rs/axum.git
synced 2025-09-30 22:41:03 +00:00
axum-extra/scheme: Use rejection macros for SchemeMissing
rejection (#3113)
This commit is contained in:
parent
8def6782fb
commit
8e78a37660
@ -1,10 +1,8 @@
|
|||||||
//! Extractor that parses the scheme of a request.
|
//! Extractor that parses the scheme of a request.
|
||||||
//! See [`Scheme`] for more details.
|
//! See [`Scheme`] for more details.
|
||||||
|
|
||||||
use axum::{
|
use axum::extract::FromRequestParts;
|
||||||
extract::FromRequestParts,
|
use axum_core::__define_rejection as define_rejection;
|
||||||
response::{IntoResponse, Response},
|
|
||||||
};
|
|
||||||
use http::{
|
use http::{
|
||||||
header::{HeaderMap, FORWARDED},
|
header::{HeaderMap, FORWARDED},
|
||||||
request::Parts,
|
request::Parts,
|
||||||
@ -23,15 +21,12 @@ const X_FORWARDED_PROTO_HEADER_KEY: &str = "X-Forwarded-Proto";
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct Scheme(pub String);
|
pub struct Scheme(pub String);
|
||||||
|
|
||||||
/// Rejection type used if the [`Scheme`] extractor is unable to
|
define_rejection! {
|
||||||
/// resolve a scheme.
|
#[status = BAD_REQUEST]
|
||||||
#[derive(Debug)]
|
#[body = "No scheme found in request"]
|
||||||
pub struct SchemeMissing;
|
/// Rejection type used if the [`Scheme`] extractor is unable to
|
||||||
|
/// resolve a scheme.
|
||||||
impl IntoResponse for SchemeMissing {
|
pub struct SchemeMissing;
|
||||||
fn into_response(self) -> Response {
|
|
||||||
(http::StatusCode::BAD_REQUEST, "No scheme found in request").into_response()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S> FromRequestParts<S> for Scheme
|
impl<S> FromRequestParts<S> for Scheme
|
||||||
|
Loading…
x
Reference in New Issue
Block a user