actix / actix/actix-web

Setting the path_filter and show_files_listing, but list page still show all files.

Aberta
#3,207 3 comentários 0 reações 0 responsáveis Ver no GitHub
A-files C-improvement good-first-issue
Linguagem predominante
Rust
Estrelas
24.8k
Forks
1.9k
Merge médio
23h 10min
PRs com merge (30d)
26

Descrição

```rs
Files::new("/", EXAMPLES_DIR)
.path_filter(|n, _| {
println!("{:?}", n);
let s = n.to_str().unwrap();
if s == "lib.rs" || s == "" {
true
} else {
false
}
})
.show_files_listing(),
```
## Expected Behavior
Only display the files that pass the filter, as in the example above, only the lib.rs file should be displayed.

## Current Behavior
![image](https://github.com/actix/actix-web/assets/19884146/32cc8e41-d54a-4140-bc61-f977da14ae3c)
Display all files, but only those passed by the filter can be accessed.

## Possible Solution
Add a filter parameter to the DirectoryRenderer function, or add a filter field to the Directory.

## Steps to Reproduce (for bugs)

```rs
use actix_files::Files;
use actix_web::{get, guard, middleware, App, HttpServer, Responder};
const EXAMPLES_DIR: &str = concat![env!("CARGO_MANIFEST_DIR"), "/src"];

#[actix_web::main]
async fn main() -> std::io::Result<()> {
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));

log::info!("starting HTTP server at http://localhost:8080");

HttpServer::new(|| {
App::new()
.service(
Files::new("/", EXAMPLES_DIR)
.path_filter(|n, _| {
println!("{:?}", n);
let s = n.to_str().unwrap();
if s == "lib.rs" || s == "" {
true
} else {
false
}
})
.show_files_listing(),
)
.wrap(middleware::Logger::default())
})
.bind(("127.0.0.1", 8080))?
.run()
.await
}

```
## Context
When I set a filter, it indicates that I don't want users to be aware of the existence of certain files. However, these files are still displayed on the list page and are inaccessible, which can confuse users.

## Your Environment
- Rust Version (I.e, output of `rustc -V`): rustc 1.76.0-nightly (1e9dda77b 2023-11-22)
- Actix Web Version: e95c8fe5a6d466ba674ea2ea35c0c4d18e1bb9d0

Guia de contribuição

Abrir o guia de contribuição

Direção de pesquisa

The reproduction uses Files::new with path_filter and show_files_listing; start by running it, then trace the directory-listing path through DirectoryRenderer and Directory. Done means the listing omits files rejected by path_filter while access behavior remains consistent with that filter.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
rust
Domínio
backend
Tipo de issue
Bug
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Ativa
Clareza
Razoavelmente clara
Facilidade para iniciantes
68/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.