diff --git a/actix-files/src/files.rs b/actix-files/src/files.rs index b1405d0d4..e04d1e134 100644 --- a/actix-files/src/files.rs +++ b/actix-files/src/files.rs @@ -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(mut self, f: F) -> Self where F: Fn(&Path, &RequestHead) -> bool + 'static,