Move TypedHeader to axum-extra (#1850)

Co-authored-by: Michael Scofield <[email protected]>
Co-authored-by: Jonas Platte <[email protected]>
This commit is contained in:
David Pedersen
2023-04-21 17:45:31 +02:00
co-authored by Michael Scofield Jonas Platte
parent 173f9f72b0
commit 877e3fe4de
48 changed files with 227 additions and 246 deletions
+12 -10
View File
@@ -139,15 +139,19 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// ```
/// use axum::{
/// async_trait,
/// extract::{Request, FromRequest},
/// headers::{authorization::Bearer, Authorization},
/// extract::{Path, Request, FromRequest},
/// response::{IntoResponse, Response},
/// body::Body,
/// Json, RequestExt, TypedHeader,
/// Json, RequestExt,
/// };
/// use axum_extra::{
/// TypedHeader,
/// headers::{authorization::Bearer, Authorization},
/// };
/// use std::collections::HashMap;
///
/// struct MyExtractor<T> {
/// bearer_token: String,
/// path_params: HashMap<String, String>,
/// payload: T,
/// }
///
@@ -161,9 +165,10 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// type Rejection = Response;
///
/// async fn from_request(mut req: Request, _state: &S) -> Result<Self, Self::Rejection> {
/// let TypedHeader(auth_header) = req
/// .extract_parts::<TypedHeader<Authorization<Bearer>>>()
/// let path_params = req
/// .extract_parts::<Path<_>>()
/// .await
/// .map(|Path(path_params)| path_params)
/// .map_err(|err| err.into_response())?;
///
/// let Json(payload) = req
@@ -171,10 +176,7 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// .await
/// .map_err(|err| err.into_response())?;
///
/// Ok(Self {
/// bearer_token: auth_header.token().to_owned(),
/// payload,
/// })
/// Ok(Self { path_params, payload })
/// }
/// }
/// ```
+6 -7
View File
@@ -17,9 +17,8 @@ pub trait RequestPartsExt: sealed::Sealed + Sized {
///
/// ```
/// use axum::{
/// extract::{Query, TypedHeader, FromRequestParts},
/// extract::{Query, Path, FromRequestParts},
/// response::{Response, IntoResponse},
/// headers::UserAgent,
/// http::request::Parts,
/// RequestPartsExt,
/// async_trait,
@@ -27,7 +26,7 @@ pub trait RequestPartsExt: sealed::Sealed + Sized {
/// use std::collections::HashMap;
///
/// struct MyExtractor {
/// user_agent: String,
/// path_params: HashMap<String, String>,
/// query_params: HashMap<String, String>,
/// }
///
@@ -39,10 +38,10 @@ pub trait RequestPartsExt: sealed::Sealed + Sized {
/// type Rejection = Response;
///
/// async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
/// let user_agent = parts
/// .extract::<TypedHeader<UserAgent>>()
/// let path_params = parts
/// .extract::<Path<HashMap<String, String>>>()
/// .await
/// .map(|user_agent| user_agent.as_str().to_owned())
/// .map(|Path(path_params)| path_params)
/// .map_err(|err| err.into_response())?;
///
/// let query_params = parts
@@ -51,7 +50,7 @@ pub trait RequestPartsExt: sealed::Sealed + Sized {
/// .map(|Query(params)| params)
/// .map_err(|err| err.into_response())?;
///
/// Ok(MyExtractor { user_agent, query_params })
/// Ok(MyExtractor { path_params, query_params })
/// }
/// }
/// ```