mirror of
https://github.com/actix/actix-web.git
synced 2024-11-25 11:01:14 +00:00
try path config from Data as well
This commit is contained in:
parent
c7639bc3be
commit
93754f307f
3 changed files with 15 additions and 2 deletions
|
@ -40,14 +40,23 @@ impl Directory {
|
||||||
pub(crate) type DirectoryRenderer =
|
pub(crate) type DirectoryRenderer =
|
||||||
dyn Fn(&Directory, &HttpRequest) -> Result<ServiceResponse, io::Error>;
|
dyn Fn(&Directory, &HttpRequest) -> Result<ServiceResponse, io::Error>;
|
||||||
|
|
||||||
// show file url as relative to static path
|
/// Returns percent encoded file URL path.
|
||||||
macro_rules! encode_file_url {
|
macro_rules! encode_file_url {
|
||||||
($path:ident) => {
|
($path:ident) => {
|
||||||
utf8_percent_encode(&$path, CONTROLS)
|
utf8_percent_encode(&$path, CONTROLS)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// " -- " & -- & ' -- ' < -- < > -- > / -- /
|
/// Returns HTML entity encoded formatter.
|
||||||
|
///
|
||||||
|
/// ```plain
|
||||||
|
/// " => "
|
||||||
|
/// & => &
|
||||||
|
/// ' => '
|
||||||
|
/// < => <
|
||||||
|
/// > => >
|
||||||
|
/// / => /
|
||||||
|
/// ```
|
||||||
macro_rules! encode_file_name {
|
macro_rules! encode_file_name {
|
||||||
($entry:ident) => {
|
($entry:ident) => {
|
||||||
escape_html_entity(&$entry.file_name().to_string_lossy(), Html)
|
escape_html_entity(&$entry.file_name().to_string_lossy(), Html)
|
||||||
|
|
|
@ -340,6 +340,7 @@ mod tests {
|
||||||
assert_eq!(q.requote(b"/a%25b%2Bc").unwrap(), "/a%b+c");
|
assert_eq!(q.requote(b"/a%25b%2Bc").unwrap(), "/a%b+c");
|
||||||
assert_eq!(q.requote(b"/a%2fb").unwrap(), "/a%2fb");
|
assert_eq!(q.requote(b"/a%2fb").unwrap(), "/a%2fb");
|
||||||
assert_eq!(q.requote(b"/a%2Fb").unwrap(), "/a%2Fb");
|
assert_eq!(q.requote(b"/a%2Fb").unwrap(), "/a%2Fb");
|
||||||
|
assert_eq!(q.requote(b"/a%0Ab").unwrap(), "/a\nb");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -9,6 +9,7 @@ use serde::de;
|
||||||
use crate::{
|
use crate::{
|
||||||
dev::Payload,
|
dev::Payload,
|
||||||
error::{Error, ErrorNotFound, PathError},
|
error::{Error, ErrorNotFound, PathError},
|
||||||
|
web::Data,
|
||||||
FromRequest, HttpRequest,
|
FromRequest, HttpRequest,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -102,6 +103,7 @@ where
|
||||||
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::<PathConfig>()
|
.app_data::<PathConfig>()
|
||||||
|
.or_else(|| req.app_data::<Data<PathConfig>>().map(Data::get_ref))
|
||||||
.and_then(|c| c.err_handler.clone());
|
.and_then(|c| c.err_handler.clone());
|
||||||
|
|
||||||
ready(
|
ready(
|
||||||
|
@ -113,6 +115,7 @@ where
|
||||||
Request path: {:?}",
|
Request path: {:?}",
|
||||||
req.path()
|
req.path()
|
||||||
);
|
);
|
||||||
|
|
||||||
if let Some(error_handler) = error_handler {
|
if let Some(error_handler) = error_handler {
|
||||||
let e = PathError::Deserialize(err);
|
let e = PathError::Deserialize(err);
|
||||||
(error_handler)(e, req)
|
(error_handler)(e, req)
|
||||||
|
|
Loading…
Reference in a new issue