Backport #5537 Remove a double slash in the HTTPS redirect with Let's Encrypt (#5539)

Before:

$ curl 0.0.0.0:3001
<a href="https://gitea.example.com:3000//">Found</a>.

After:

$ curl 0.0.0.0:3001
<a href="https://gitea.example.com:3000/">Found</a>.

Fixes #5536
This commit is contained in:
Greg Karékinian 2018-12-13 16:42:38 +01:00 committed by techknowlogick
parent 800271ee1f
commit 200b974e19

View file

@ -102,7 +102,10 @@ func runLetsEncryptFallbackHandler(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Use HTTPS", http.StatusBadRequest) http.Error(w, "Use HTTPS", http.StatusBadRequest)
return return
} }
target := setting.AppURL + r.URL.RequestURI() // Remove the trailing slash at the end of setting.AppURL, the request
// URI always contains a leading slash, which would result in a double
// slash
target := strings.TrimRight(setting.AppURL, "/") + r.URL.RequestURI()
http.Redirect(w, r, target, http.StatusFound) http.Redirect(w, r, target, http.StatusFound)
} }