mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-16 14:33:02 +01:00
Move TypedHeader
into root (#803)
This commit is contained in:
parent
2428d99081
commit
24359ebd4d
5 changed files with 38 additions and 13 deletions
|
@ -72,11 +72,8 @@ pub use self::request_parts::OriginalUri;
|
|||
pub use self::ws::WebSocketUpgrade;
|
||||
|
||||
#[cfg(feature = "headers")]
|
||||
mod typed_header;
|
||||
|
||||
#[cfg(feature = "headers")]
|
||||
#[doc(inline)]
|
||||
pub use self::typed_header::TypedHeader;
|
||||
#[doc(no_inline)]
|
||||
pub use crate::TypedHeader;
|
||||
|
||||
pub(crate) fn has_content_type<B>(
|
||||
req: &RequestParts<B>,
|
||||
|
|
|
@ -235,4 +235,4 @@ where
|
|||
}
|
||||
|
||||
#[cfg(feature = "headers")]
|
||||
pub use super::typed_header::{TypedHeaderRejection, TypedHeaderRejectionReason};
|
||||
pub use crate::typed_header::{TypedHeaderRejection, TypedHeaderRejectionReason};
|
||||
|
|
|
@ -395,6 +395,8 @@ pub(crate) mod macros;
|
|||
mod extension;
|
||||
#[cfg(feature = "json")]
|
||||
mod json;
|
||||
#[cfg(feature = "headers")]
|
||||
mod typed_header;
|
||||
mod util;
|
||||
|
||||
pub mod body;
|
||||
|
@ -426,5 +428,9 @@ pub use self::json::Json;
|
|||
#[doc(inline)]
|
||||
pub use self::routing::Router;
|
||||
|
||||
#[doc(inline)]
|
||||
#[cfg(feature = "headers")]
|
||||
pub use self::typed_header::TypedHeader;
|
||||
|
||||
#[doc(inline)]
|
||||
pub use axum_core::{BoxError, Error};
|
||||
|
|
|
@ -11,6 +11,10 @@ pub mod sse;
|
|||
#[cfg(feature = "json")]
|
||||
pub use crate::Json;
|
||||
|
||||
#[doc(no_inline)]
|
||||
#[cfg(feature = "headers")]
|
||||
pub use crate::TypedHeader;
|
||||
|
||||
#[doc(no_inline)]
|
||||
pub use crate::Extension;
|
||||
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
use super::{FromRequest, RequestParts};
|
||||
use crate::extract::{FromRequest, RequestParts};
|
||||
use async_trait::async_trait;
|
||||
use axum_core::response::{IntoResponse, IntoResponseParts, Response, ResponseParts};
|
||||
use headers::HeaderMapExt;
|
||||
use http::header::{HeaderName, HeaderValue};
|
||||
use std::ops::Deref;
|
||||
|
||||
/// Extractor that extracts a typed header value from [`headers`].
|
||||
/// Extractor and response that works with typed header values from [`headers`].
|
||||
///
|
||||
/// # As extractor
|
||||
///
|
||||
/// In general, it's recommended to extract only the needed headers via `TypedHeader` rather than
|
||||
/// removing all headers with the `HeaderMap` extractor.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// use axum::{
|
||||
/// extract::TypedHeader,
|
||||
/// TypedHeader,
|
||||
/// headers::UserAgent,
|
||||
/// routing::get,
|
||||
/// Router,
|
||||
|
@ -31,7 +31,24 @@ use std::ops::Deref;
|
|||
/// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
|
||||
/// # };
|
||||
/// ```
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "headers")))]
|
||||
///
|
||||
/// # As response
|
||||
///
|
||||
/// ```rust
|
||||
/// use axum::{
|
||||
/// TypedHeader,
|
||||
/// response::IntoResponse,
|
||||
/// headers::ContentType,
|
||||
/// };
|
||||
///
|
||||
/// async fn handler() -> impl IntoResponse {
|
||||
/// (
|
||||
/// TypedHeader(ContentType::text_utf8()),
|
||||
/// "Hello, World!",
|
||||
/// )
|
||||
/// }
|
||||
/// ```
|
||||
#[cfg(feature = "headers")]
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct TypedHeader<T>(pub T);
|
||||
|
||||
|
@ -127,7 +144,8 @@ impl TypedHeaderRejection {
|
|||
}
|
||||
}
|
||||
|
||||
/// Additional information regarding a [`TypedHeaderRejection`](super::TypedHeaderRejection)
|
||||
/// Additional information regarding a [`TypedHeaderRejection`]
|
||||
#[cfg(feature = "headers")]
|
||||
#[derive(Debug)]
|
||||
#[non_exhaustive]
|
||||
pub enum TypedHeaderRejectionReason {
|
Loading…
Reference in a new issue