aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2026-02-05 19:29:05 +0700
committerShulhan <ms@kilabit.info>2026-02-05 19:29:05 +0700
commitfad13afac8b51e61ad5465c88021895a95403a15 (patch)
tree93423275360d21013b485f2f141f9c00d1a42827
parent3734420eec485bca8c18243741e1ad2a683515b7 (diff)
downloadpakakeh.go-fad13afac8b51e61ad5465c88021895a95403a15.tar.xz
lib/http: change HandleFS redirect status code to 301 Moved Permanently
According to MDN [Redirections in HTTP], the HTTP status 302 Found use case is The Web page is temporarily unavailable for unforeseen reasons. This probably to re-route the page until the original page is fixed. While HTTP status 301 is for Reorganization of a website. Since the redirection in HandleFS only happen when user access directory without slash, we should make it permanent. [Redirections in HTTP]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Redirections
-rw-r--r--lib/http/server.go2
-rw-r--r--lib/http/testdata/Server_HandleFS_test.txt12
2 files changed, 7 insertions, 7 deletions
diff --git a/lib/http/server.go b/lib/http/server.go
index edc99cf7..64ac5c14 100644
--- a/lib/http/server.go
+++ b/lib/http/server.go
@@ -481,7 +481,7 @@ func (srv *Server) HandleFS(res http.ResponseWriter, req *http.Request) {
// If request path is a directory and it is not end with
// slash, redirect request to location with slash to allow
// relative links works inside the HTML content.
- http.Redirect(res, req, redirectURL.String(), http.StatusFound)
+ http.Redirect(res, req, redirectURL.String(), http.StatusMovedPermanently)
return
}
if srv.Options.HandleFS != nil {
diff --git a/lib/http/testdata/Server_HandleFS_test.txt b/lib/http/testdata/Server_HandleFS_test.txt
index 8b2173ef..f0c57117 100644
--- a/lib/http/testdata/Server_HandleFS_test.txt
+++ b/lib/http/testdata/Server_HandleFS_test.txt
@@ -14,32 +14,32 @@ Content-Type: text/html; charset=utf-8
</html>
<<< /dir
-HTTP/1.1 302 Found
+HTTP/1.1 301 Moved Permanently
Connection: close
Content-Type: text/html; charset=utf-8
Location: /dir/
-<a href="/dir/">Found</a>.
+<a href="/dir/">Moved Permanently</a>.
<<< /dir?q=abc
-HTTP/1.1 302 Found
+HTTP/1.1 301 Moved Permanently
Connection: close
Content-Type: text/html; charset=utf-8
Location: /dir/?q=abc
-<a href="/dir/?q=abc">Found</a>.
+<a href="/dir/?q=abc">Moved Permanently</a>.
<<< /dir?q=abc#fgh
-HTTP/1.1 302 Found
+HTTP/1.1 301 Moved Permanently
Connection: close
Content-Type: text/html; charset=utf-8
Location: /dir/?q=abc#fgh
-<a href="/dir/?q=abc#fgh">Found</a>.
+<a href="/dir/?q=abc#fgh">Moved Permanently</a>.