mirror of https://github.com/fafhrd91/actix-web
Remove `FromRequest::Config` which should not be exposed as type
This commit is contained in:
parent
b1de196509
commit
fe6f0aee6d
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
Alternatively, explicitly require trailing slashes: `NormalizePath::new(TrailingSlash::Always)`.
|
Alternatively, explicitly require trailing slashes: `NormalizePath::new(TrailingSlash::Always)`.
|
||||||
|
|
||||||
|
* The `type Config` of `FromRequest` was removed.
|
||||||
|
|
||||||
## 3.0.0
|
## 3.0.0
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,6 @@ impl AsRef<Path> for PathBufWrap {
|
||||||
impl FromRequest for PathBufWrap {
|
impl FromRequest for PathBufWrap {
|
||||||
type Error = UriSegmentError;
|
type Error = UriSegmentError;
|
||||||
type Future = Ready<Result<Self, Self::Error>>;
|
type Future = Ready<Result<Self, Self::Error>>;
|
||||||
type Config = ();
|
|
||||||
|
|
||||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||||
ready(req.match_info().path().parse())
|
ready(req.match_info().path().parse())
|
||||||
|
|
|
@ -33,7 +33,6 @@ use crate::server::Multipart;
|
||||||
impl FromRequest for Multipart {
|
impl FromRequest for Multipart {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Ready<Result<Multipart, Error>>;
|
type Future = Ready<Result<Multipart, Error>>;
|
||||||
type Config = ();
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||||
|
|
|
@ -114,7 +114,6 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: ?Sized + 'static> FromRequest for Data<T> {
|
impl<T: ?Sized + 'static> FromRequest for Data<T> {
|
||||||
type Config = ();
|
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Ready<Result<Self, Error>>;
|
type Future = Ready<Result<Self, Error>>;
|
||||||
|
|
||||||
|
|
|
@ -15,9 +15,6 @@ use crate::{dev::Payload, Error, HttpRequest};
|
||||||
///
|
///
|
||||||
/// Types that implement this trait can be used with `Route` handlers.
|
/// Types that implement this trait can be used with `Route` handlers.
|
||||||
pub trait FromRequest: Sized {
|
pub trait FromRequest: Sized {
|
||||||
/// Configuration for this extractor.
|
|
||||||
type Config: Default + 'static;
|
|
||||||
|
|
||||||
/// The associated error which can be returned.
|
/// The associated error which can be returned.
|
||||||
type Error: Into<Error>;
|
type Error: Into<Error>;
|
||||||
|
|
||||||
|
@ -33,14 +30,6 @@ pub trait FromRequest: Sized {
|
||||||
fn extract(req: &HttpRequest) -> Self::Future {
|
fn extract(req: &HttpRequest) -> Self::Future {
|
||||||
Self::from_request(req, &mut Payload::None)
|
Self::from_request(req, &mut Payload::None)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create and configure config instance.
|
|
||||||
fn configure<F>(f: F) -> Self::Config
|
|
||||||
where
|
|
||||||
F: FnOnce(Self::Config) -> Self::Config,
|
|
||||||
{
|
|
||||||
f(Self::Config::default())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Optionally extract a field from the request
|
/// Optionally extract a field from the request
|
||||||
|
@ -64,7 +53,6 @@ pub trait FromRequest: Sized {
|
||||||
/// impl FromRequest for Thing {
|
/// impl FromRequest for Thing {
|
||||||
/// type Error = Error;
|
/// type Error = Error;
|
||||||
/// type Future = Ready<Result<Self, Self::Error>>;
|
/// type Future = Ready<Result<Self, Self::Error>>;
|
||||||
/// type Config = ();
|
|
||||||
///
|
///
|
||||||
/// fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
/// fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
||||||
/// if rand::random() {
|
/// if rand::random() {
|
||||||
|
@ -99,7 +87,6 @@ where
|
||||||
{
|
{
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = FromRequestOptFuture<T::Future>;
|
type Future = FromRequestOptFuture<T::Future>;
|
||||||
type Config = T::Config;
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||||
|
@ -156,7 +143,6 @@ where
|
||||||
/// impl FromRequest for Thing {
|
/// impl FromRequest for Thing {
|
||||||
/// type Error = Error;
|
/// type Error = Error;
|
||||||
/// type Future = Ready<Result<Thing, Error>>;
|
/// type Future = Ready<Result<Thing, Error>>;
|
||||||
/// type Config = ();
|
|
||||||
///
|
///
|
||||||
/// fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
/// fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
||||||
/// if rand::random() {
|
/// if rand::random() {
|
||||||
|
@ -189,7 +175,6 @@ where
|
||||||
{
|
{
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = FromRequestResFuture<T::Future>;
|
type Future = FromRequestResFuture<T::Future>;
|
||||||
type Config = T::Config;
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||||
|
@ -222,7 +207,6 @@ where
|
||||||
impl FromRequest for () {
|
impl FromRequest for () {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Ready<Result<(), Error>>;
|
type Future = Ready<Result<(), Error>>;
|
||||||
type Config = ();
|
|
||||||
|
|
||||||
fn from_request(_: &HttpRequest, _: &mut Payload) -> Self::Future {
|
fn from_request(_: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||||
ready(Ok(()))
|
ready(Ok(()))
|
||||||
|
@ -262,7 +246,6 @@ macro_rules! tuple_from_req ({$fut_type:ident, $(($n:tt, $T:ident)),+} => {
|
||||||
{
|
{
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = $fut_type<$($T),+>;
|
type Future = $fut_type<$($T),+>;
|
||||||
type Config = ($($T::Config),+);
|
|
||||||
|
|
||||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||||
$fut_type {
|
$fut_type {
|
||||||
|
|
|
@ -375,7 +375,6 @@ impl Drop for HttpRequest {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
impl FromRequest for HttpRequest {
|
impl FromRequest for HttpRequest {
|
||||||
type Config = ();
|
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Ready<Result<Self, Error>>;
|
type Future = Ready<Result<Self, Error>>;
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,6 @@ impl<T: Clone + 'static> Deref for ReqData<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Clone + 'static> FromRequest for ReqData<T> {
|
impl<T: Clone + 'static> FromRequest for ReqData<T> {
|
||||||
type Config = ();
|
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Ready<Result<Self, Error>>;
|
type Future = Ready<Result<Self, Error>>;
|
||||||
|
|
||||||
|
|
|
@ -173,7 +173,7 @@ where
|
||||||
/// Resource data overrides data registered by `App::data()` method.
|
/// Resource data overrides data registered by `App::data()` method.
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// use actix_web::{web, App, FromRequest};
|
/// use actix_web::{web, App};
|
||||||
///
|
///
|
||||||
/// /// extract text data from request
|
/// /// extract text data from request
|
||||||
/// async fn index(body: String) -> String {
|
/// async fn index(body: String) -> String {
|
||||||
|
@ -184,9 +184,7 @@ where
|
||||||
/// let app = App::new().service(
|
/// let app = App::new().service(
|
||||||
/// web::resource("/index.html")
|
/// web::resource("/index.html")
|
||||||
/// // limit size of the payload
|
/// // limit size of the payload
|
||||||
/// .data(String::configure(|cfg| {
|
/// .data(web::PayloadConfig::new(4096))
|
||||||
/// cfg.limit(4096)
|
|
||||||
/// }))
|
|
||||||
/// .route(
|
/// .route(
|
||||||
/// web::get()
|
/// web::get()
|
||||||
/// // register handler
|
/// // register handler
|
||||||
|
|
|
@ -187,7 +187,6 @@ where
|
||||||
{
|
{
|
||||||
type Error = EitherExtractError<L::Error, R::Error>;
|
type Error = EitherExtractError<L::Error, R::Error>;
|
||||||
type Future = EitherExtractFut<L, R>;
|
type Future = EitherExtractFut<L, R>;
|
||||||
type Config = ();
|
|
||||||
|
|
||||||
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut dev::Payload) -> Self::Future {
|
||||||
EitherExtractFut {
|
EitherExtractFut {
|
||||||
|
|
|
@ -121,20 +121,12 @@ impl<T> FromRequest for Form<T>
|
||||||
where
|
where
|
||||||
T: DeserializeOwned + 'static,
|
T: DeserializeOwned + 'static,
|
||||||
{
|
{
|
||||||
type Config = FormConfig;
|
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = FormExtractFut<T>;
|
type Future = FormExtractFut<T>;
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||||
let (limit, err_handler) = req
|
let FormConfig { limit, err_handler } = FormConfig::from_req(req).clone();
|
||||||
.app_data::<Self::Config>()
|
|
||||||
.or_else(|| {
|
|
||||||
req.app_data::<web::Data<Self::Config>>()
|
|
||||||
.map(|d| d.as_ref())
|
|
||||||
})
|
|
||||||
.map(|c| (c.limit, c.err_handler.clone()))
|
|
||||||
.unwrap_or((16384, None));
|
|
||||||
|
|
||||||
FormExtractFut {
|
FormExtractFut {
|
||||||
fut: UrlEncoded::new(req, payload).limit(limit),
|
fut: UrlEncoded::new(req, payload).limit(limit),
|
||||||
|
@ -236,14 +228,25 @@ impl FormConfig {
|
||||||
self.err_handler = Some(Rc::new(f));
|
self.err_handler = Some(Rc::new(f));
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Extract payload config from app data. Check both `T` and `Data<T>`, in that order, and fall
|
||||||
|
/// back to the default payload config.
|
||||||
|
fn from_req(req: &HttpRequest) -> &Self {
|
||||||
|
req.app_data::<Self>()
|
||||||
|
.or_else(|| req.app_data::<web::Data<Self>>().map(|d| d.as_ref()))
|
||||||
|
.unwrap_or(&DEFAULT_CONFIG)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Allow shared refs used as default.
|
||||||
|
const DEFAULT_CONFIG: FormConfig = FormConfig {
|
||||||
|
limit: 16_384, // 2^14 bytes (~16kB)
|
||||||
|
err_handler: None,
|
||||||
|
};
|
||||||
|
|
||||||
impl Default for FormConfig {
|
impl Default for FormConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
FormConfig {
|
DEFAULT_CONFIG.clone()
|
||||||
limit: 16_384, // 2^14 bytes (~16kB)
|
|
||||||
err_handler: None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,6 @@ where
|
||||||
{
|
{
|
||||||
type Error = ParseError;
|
type Error = ParseError;
|
||||||
type Future = Ready<Result<Self, Self::Error>>;
|
type Future = Ready<Result<Self, Self::Error>>;
|
||||||
type Config = ();
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||||
|
|
|
@ -139,7 +139,6 @@ where
|
||||||
{
|
{
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = JsonExtractFut<T>;
|
type Future = JsonExtractFut<T>;
|
||||||
type Config = JsonConfig;
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||||
|
|
|
@ -98,12 +98,11 @@ where
|
||||||
{
|
{
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Ready<Result<Self, Self::Error>>;
|
type Future = Ready<Result<Self, Self::Error>>;
|
||||||
type Config = PathConfig;
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||||
let error_handler = req
|
let error_handler = req
|
||||||
.app_data::<Self::Config>()
|
.app_data::<PathConfig>()
|
||||||
.map(|c| c.ehandler.clone())
|
.map(|c| c.ehandler.clone())
|
||||||
.unwrap_or(None);
|
.unwrap_or(None);
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,6 @@ impl Stream for Payload {
|
||||||
|
|
||||||
/// See [here](#usage) for example of usage as an extractor.
|
/// See [here](#usage) for example of usage as an extractor.
|
||||||
impl FromRequest for Payload {
|
impl FromRequest for Payload {
|
||||||
type Config = PayloadConfig;
|
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Ready<Result<Payload, Error>>;
|
type Future = Ready<Result<Payload, Error>>;
|
||||||
|
|
||||||
|
@ -89,7 +88,6 @@ impl FromRequest for Payload {
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
impl FromRequest for Bytes {
|
impl FromRequest for Bytes {
|
||||||
type Config = PayloadConfig;
|
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Either<BytesExtractFut, Ready<Result<Bytes, Error>>>;
|
type Future = Either<BytesExtractFut, Ready<Result<Bytes, Error>>>;
|
||||||
|
|
||||||
|
@ -138,7 +136,6 @@ impl<'a> Future for BytesExtractFut {
|
||||||
/// format!("Body {}!", text)
|
/// format!("Body {}!", text)
|
||||||
/// }
|
/// }
|
||||||
impl FromRequest for String {
|
impl FromRequest for String {
|
||||||
type Config = PayloadConfig;
|
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Either<StringExtractFut, Ready<Result<String, Error>>>;
|
type Future = Either<StringExtractFut, Ready<Result<String, Error>>>;
|
||||||
|
|
||||||
|
|
|
@ -113,12 +113,11 @@ where
|
||||||
{
|
{
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
type Future = Ready<Result<Self, Error>>;
|
type Future = Ready<Result<Self, Error>>;
|
||||||
type Config = QueryConfig;
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||||
let error_handler = req
|
let error_handler = req
|
||||||
.app_data::<Self::Config>()
|
.app_data::<QueryConfig>()
|
||||||
.map(|c| c.err_handler.clone())
|
.map(|c| c.err_handler.clone())
|
||||||
.unwrap_or(None);
|
.unwrap_or(None);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue