more docs

This commit is contained in:
Ali MJ Al-Nasrawy 2021-06-23 01:24:28 +03:00
parent 173ea9acf2
commit 7e60a5bb2e
1 changed files with 18 additions and 1 deletions

View File

@ -162,8 +162,25 @@ impl Files {
/// Sets path filtering closure.
///
/// When a path doen't pass the filter, [`Files::default_handler`] is called if set, otherwise,
/// The path provided to the closure is relative to `serve_from` path.
/// You can safely join this path with the `serve_from` path to get the real path.
/// However, the real path may not exist since the filter is called before checking path existence.
///
/// When a path doesn't pass the filter, [`Files::default_handler`] is called if set, otherwise,
/// `404 NotFound` is returned.
/// ```
/// use std::path::Path;
/// use actix_files::Files;
///
/// let files_service = Files::new("/", "./static").path_filter(|path, _| {
/// path.components.count() == 1
/// && Path::new("./static")
/// .join(path)
/// .symlink_metadata()
/// .map(|m| m.file_type().is_symlink())
/// .unwrap_or(false)
/// });
/// ```
pub fn path_filter<F>(mut self, f: F) -> Self
where
F: Fn(&Path, &RequestHead) -> bool + 'static,