Struct poem::web::TypedHeader
source · [−]pub struct TypedHeader<T>(pub T);
Expand description
An extractor that extracts a typed header value.
Errors
Example
use poem::{
get, handler,
http::{header, StatusCode},
test::TestClient,
web::{headers::Host, TypedHeader},
Endpoint, Request, Route,
};
#[handler]
fn index(TypedHeader(host): TypedHeader<Host>) -> String {
host.hostname().to_string()
}
let app = Route::new().at("/", get(index));
let cli = TestClient::new(app);
let resp = cli
.get("/")
.header(header::HOST, "example.com")
.send()
.await;
resp.assert_status_is_ok();
resp.assert_text("example.com").await;
Tuple Fields
0: T
Trait Implementations
sourceimpl<T: Debug> Debug for TypedHeader<T>
impl<T: Debug> Debug for TypedHeader<T>
sourceimpl<T> Deref for TypedHeader<T>
impl<T> Deref for TypedHeader<T>
sourceimpl<T> DerefMut for TypedHeader<T>
impl<T> DerefMut for TypedHeader<T>
sourceimpl<'a, T: Header> FromRequest<'a> for TypedHeader<T>
impl<'a, T: Header> FromRequest<'a> for TypedHeader<T>
sourcefn from_request<'life0, 'async_trait>(
req: &'a Request,
_body: &'life0 mut RequestBody
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>> where
'a: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
fn from_request<'life0, 'async_trait>(
req: &'a Request,
_body: &'life0 mut RequestBody
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>> where
'a: 'async_trait,
'life0: 'async_trait,
Self: 'async_trait,
Extract from request head and body.
Auto Trait Implementations
impl<T> RefUnwindSafe for TypedHeader<T> where
T: RefUnwindSafe,
impl<T> Send for TypedHeader<T> where
T: Send,
impl<T> Sync for TypedHeader<T> where
T: Sync,
impl<T> Unpin for TypedHeader<T> where
T: Unpin,
impl<T> UnwindSafe for TypedHeader<T> where
T: UnwindSafe,
Blanket Implementations
impl<T, A, P> Access<T> for P where
A: Access<T>,
P: Deref<Target = A>,
impl<T, A, P> Access<T> for P where
A: Access<T>,
P: Deref<Target = A>,
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, A> DynAccess<T> for A where
A: Access<T>,
<A as Access<T>>::Guard: 'static,
impl<T, A> DynAccess<T> for A where
A: Access<T>,
<A as Access<T>>::Guard: 'static,
fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
The equivalent of [Access::load
].
sourceimpl<T> FutureExt for T
impl<T> FutureExt for T
sourcefn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
sourcefn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more