Skip to content

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

@AseCoder

Description

@AseCoder

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-filesproject: actix-filesC-tweakCategory: tweak / trivial change

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions