pub struct Header<H: DocumentedHeader>(pub String, pub PhantomData<H>);Expand description
Extracts a header value by name, where the name is supplied
type-level via DocumentedHeader::name. Modeled after
axum_extra::TypedHeader
but using our own DocumentedHeader trait so the macro pass
can resolve the wire name at runtime without depending on the
foreign headers crate.
§Example
ⓘ
use doxa::{DocumentedHeader, Header};
pub struct XApiKey;
impl DocumentedHeader for XApiKey {
fn name() -> &'static str { "X-Api-Key" }
fn description() -> &'static str { "Tenant API key" }
}
async fn handler(Header(key): Header<XApiKey>) -> &'static str {
// `key` is the raw header value as a String.
"ok"
}Handlers extracting via Header<H> are auto-registered in the
OpenAPI spec by the #[get] / #[post] / etc. macros — the
macro recognizes the wrapper type and emits a
params(DocHeaderEntry<H>) entry. No explicit headers(...)
annotation is needed for the documented case.
Tuple Fields§
§0: String§1: PhantomData<H>Trait Implementations§
Source§impl<H: DocumentedHeader> DocHeaderParams for Header<H>
impl<H: DocumentedHeader> DocHeaderParams for Header<H>
Source§impl<S, H> FromRequestParts<S> for Header<H>
impl<S, H> FromRequestParts<S> for Header<H>
Auto Trait Implementations§
impl<H> Freeze for Header<H>
impl<H> RefUnwindSafe for Header<H>where
H: RefUnwindSafe,
impl<H> Send for Header<H>where
H: Send,
impl<H> Sync for Header<H>where
H: Sync,
impl<H> Unpin for Header<H>where
H: Unpin,
impl<H> UnsafeUnpin for Header<H>
impl<H> UnwindSafe for Header<H>where
H: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
Source§type Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
If the extractor fails it’ll use this “rejection” type. A rejection is
a kind of error that can be converted into a response.
Source§fn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Perform the extraction.