forked from TrueCloudLab/rclone
serve http/webdav: redirect requests to the base url without the /
When using `--baseurl` before this patch, if a request was made to the base URL without a trailing / then rclone would return a 404 error. Unfortunately GVFS / Nautilus makes the request without the / regardless of what the user put in. This patch redirects the request to the base URL with a /. So if the user was using `--baseurl rclone` then a request to http://localhost/rclone would be redirected with a 308 response to http://localhost/rclone/ Fixes #4814
This commit is contained in:
parent
584523672c
commit
8bf4697dc2
1 changed files with 5 additions and 0 deletions
|
@ -402,6 +402,11 @@ func (s *Server) Path(w http.ResponseWriter, r *http.Request) (Path string, ok b
|
||||||
return Path, true
|
return Path, true
|
||||||
}
|
}
|
||||||
if !strings.HasPrefix(Path, s.Opt.BaseURL+"/") {
|
if !strings.HasPrefix(Path, s.Opt.BaseURL+"/") {
|
||||||
|
// Send a redirect if the BaseURL was requested without a /
|
||||||
|
if Path == s.Opt.BaseURL {
|
||||||
|
http.Redirect(w, r, s.Opt.BaseURL+"/", http.StatusPermanentRedirect)
|
||||||
|
return Path, false
|
||||||
|
}
|
||||||
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
http.Error(w, http.StatusText(http.StatusNotFound), http.StatusNotFound)
|
||||||
return Path, false
|
return Path, false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue