1
0
mirror of https://github.com/fafhrd91/actix-web synced 2025-07-01 00:44:26 +02:00
This commit is contained in:
Rob Ede
2021-10-19 01:32:58 +01:00
parent 6b3ea4fc61
commit efdf3ab1c3
8 changed files with 26 additions and 47 deletions

View File

@ -276,7 +276,7 @@ impl AcceptEncoding {
let mut encodings = raw
.replace(' ', "")
.split(',')
.filter_map(|l| AcceptEncoding::new(l))
.filter_map(AcceptEncoding::new)
.collect::<Vec<_>>();
encodings.sort();

View File

@ -102,7 +102,7 @@ where
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
let error_handler = req
.app_data::<PathConfig>()
.and_then(|c| c.ehandler.clone());
.and_then(|c| c.err_handler.clone());
ready(
de::Deserialize::deserialize(PathDeserializer::new(req.match_info()))
@ -158,9 +158,9 @@ where
/// );
/// }
/// ```
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct PathConfig {
ehandler: Option<Arc<dyn Fn(PathError, &HttpRequest) -> Error + Send + Sync>>,
err_handler: Option<Arc<dyn Fn(PathError, &HttpRequest) -> Error + Send + Sync>>,
}
impl PathConfig {
@ -169,17 +169,11 @@ impl PathConfig {
where
F: Fn(PathError, &HttpRequest) -> Error + Send + Sync + 'static,
{
self.ehandler = Some(Arc::new(f));
self.err_handler = Some(Arc::new(f));
self
}
}
impl Default for PathConfig {
fn default() -> Self {
PathConfig { ehandler: None }
}
}
#[cfg(test)]
mod tests {
use actix_router::ResourceDef;

View File

@ -167,7 +167,7 @@ impl<T: DeserializeOwned> FromRequest for Query<T> {
/// .app_data(query_cfg)
/// .service(index);
/// ```
#[derive(Clone)]
#[derive(Clone, Default)]
pub struct QueryConfig {
err_handler: Option<Arc<dyn Fn(QueryPayloadError, &HttpRequest) -> Error + Send + Sync>>,
}
@ -183,12 +183,6 @@ impl QueryConfig {
}
}
impl Default for QueryConfig {
fn default() -> Self {
QueryConfig { err_handler: None }
}
}
#[cfg(test)]
mod tests {
use actix_http::http::StatusCode;