diff options
| author | Shulhan <ms@kilabit.info> | 2023-07-09 23:44:47 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-07-09 23:44:56 +0700 |
| commit | 1009fd94d528d74a4a66d92b4d8de7746d4a10ca (patch) | |
| tree | b58e36e41573c0baf77f4df52b9f298a68ae88a4 | |
| parent | c4a7695f96267364fd129ae2691299fe7ccf8c5c (diff) | |
| download | pakakeh.go-1009fd94d528d74a4a66d92b4d8de7746d4a10ca.tar.xz | |
lib/http: fix missing query when handling redirect in HandleFS
In 06e6cbdd511c, we redirect request by adding end slash to the path
if the requested resource is directory, but somehow we miss adding the
original request query.
This changes fix this issue.
| -rw-r--r-- | lib/http/server.go | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/http/server.go b/lib/http/server.go index 3bf96049..96a2a902 100644 --- a/lib/http/server.go +++ b/lib/http/server.go @@ -490,7 +490,11 @@ 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, req.URL.Path+"/", http.StatusFound) + var redirectPath = req.URL.Path + "/" + if len(req.URL.RawQuery) > 0 { + redirectPath += "?" + req.URL.RawQuery + } + http.Redirect(res, req, redirectPath, http.StatusFound) return } |
