Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files::redirect_to_slash_directory() should use HTTP status code 308 #3543

Open
AseCoder opened this issue Jan 5, 2025 · 0 comments
Open

Comments

@AseCoder
Copy link

AseCoder commented Jan 5, 2025

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()

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant