-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
A-filesproject: actix-filesproject: actix-filesC-tweakCategory: tweak / trivial changeCategory: tweak / trivial change
Description
Expected Behavior
When serving files with actix_files::Files::new().redirect_to_slash_directory() the redirect response to the client should have status code 308 (permanent redirect) or 301 (moved permanently).
Current Behavior
Currently the response has status code 302 (found).
Steps to Reproduce (for bugs)
The culprit is this HttpResponse::Found()
actix-web/actix-files/src/service.rs
Lines 142 to 153 in 5aeb0dd
| if this.redirect_to_slash | |
| && !req.path().ends_with('/') | |
| && (this.index.is_some() || this.show_index) | |
| { | |
| let redirect_to = format!("{}/", req.path()); | |
| return Ok(req.into_response( | |
| HttpResponse::Found() | |
| .insert_header((header::LOCATION, redirect_to)) | |
| .finish(), | |
| )); | |
| } |
Context
302 is the wrong status in this case. MDN says that search engines ignore temporary redirects. In this case the redirect is permanent, because we want all requests forever and always to use a trailing slash.
Your Environment
- Rust Version 1.83.0
- Actix Web Version: 4.9.0
- Firefox Version 133
Metadata
Metadata
Assignees
Labels
A-filesproject: actix-filesproject: actix-filesC-tweakCategory: tweak / trivial changeCategory: tweak / trivial change