mirror of
https://github.com/drakkan/sftpgo.git
synced 2024-11-21 23:20:24 +00:00
httpd: webpath redirect using status found (302)
301 MovedPermanently is cached by the browser which can be annoying when it is is on base path like / while one may reuse the domain (e.g. localhost) for other apps/tests. Fixes #695 Signed-off-by: Jeremy Clerc <jeremy@clerc.io>
This commit is contained in:
parent
d2a4178846
commit
9709aed5e6
3 changed files with 8 additions and 8 deletions
|
@ -7968,19 +7968,19 @@ func TestHealthCheck(t *testing.T) {
|
|||
func TestGetWebRootMock(t *testing.T) {
|
||||
req, _ := http.NewRequest(http.MethodGet, "/", nil)
|
||||
rr := executeRequest(req)
|
||||
checkResponseCode(t, http.StatusMovedPermanently, rr)
|
||||
checkResponseCode(t, http.StatusFound, rr)
|
||||
assert.Equal(t, webClientLoginPath, rr.Header().Get("Location"))
|
||||
req, _ = http.NewRequest(http.MethodGet, webBasePath, nil)
|
||||
rr = executeRequest(req)
|
||||
checkResponseCode(t, http.StatusMovedPermanently, rr)
|
||||
checkResponseCode(t, http.StatusFound, rr)
|
||||
assert.Equal(t, webClientLoginPath, rr.Header().Get("Location"))
|
||||
req, _ = http.NewRequest(http.MethodGet, webBasePathAdmin, nil)
|
||||
rr = executeRequest(req)
|
||||
checkResponseCode(t, http.StatusMovedPermanently, rr)
|
||||
checkResponseCode(t, http.StatusFound, rr)
|
||||
assert.Equal(t, webLoginPath, rr.Header().Get("Location"))
|
||||
req, _ = http.NewRequest(http.MethodGet, webBasePathClient, nil)
|
||||
rr = executeRequest(req)
|
||||
checkResponseCode(t, http.StatusMovedPermanently, rr)
|
||||
checkResponseCode(t, http.StatusFound, rr)
|
||||
assert.Equal(t, webClientLoginPath, rr.Header().Get("Location"))
|
||||
}
|
||||
|
||||
|
|
|
@ -1649,14 +1649,14 @@ func TestWebAdminRedirect(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
rr := httptest.NewRecorder()
|
||||
testServer.Config.Handler.ServeHTTP(rr, req)
|
||||
assert.Equal(t, http.StatusMovedPermanently, rr.Code, rr.Body.String())
|
||||
assert.Equal(t, http.StatusFound, rr.Code, rr.Body.String())
|
||||
assert.Equal(t, webLoginPath, rr.Header().Get("Location"))
|
||||
|
||||
req, err = http.NewRequest(http.MethodGet, webBasePath, nil)
|
||||
assert.NoError(t, err)
|
||||
rr = httptest.NewRecorder()
|
||||
testServer.Config.Handler.ServeHTTP(rr, req)
|
||||
assert.Equal(t, http.StatusMovedPermanently, rr.Code, rr.Body.String())
|
||||
assert.Equal(t, http.StatusFound, rr.Code, rr.Body.String())
|
||||
assert.Equal(t, webLoginPath, rr.Header().Get("Location"))
|
||||
}
|
||||
|
||||
|
|
|
@ -943,7 +943,7 @@ func (s *httpdServer) sendForbiddenResponse(w http.ResponseWriter, r *http.Reque
|
|||
|
||||
func (s *httpdServer) redirectToWebPath(w http.ResponseWriter, r *http.Request, webPath string) {
|
||||
if dataprovider.HasAdmin() {
|
||||
http.Redirect(w, r, webPath, http.StatusMovedPermanently)
|
||||
http.Redirect(w, r, webPath, http.StatusFound)
|
||||
return
|
||||
}
|
||||
if s.enableWebAdmin {
|
||||
|
@ -1200,7 +1200,7 @@ func (s *httpdServer) initializeRouter() {
|
|||
if s.enableWebClient {
|
||||
s.router.Get(webBaseClientPath, func(w http.ResponseWriter, r *http.Request) {
|
||||
r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
|
||||
http.Redirect(w, r, webClientLoginPath, http.StatusMovedPermanently)
|
||||
http.Redirect(w, r, webClientLoginPath, http.StatusFound)
|
||||
})
|
||||
s.router.Get(webClientLoginPath, s.handleClientWebLogin)
|
||||
s.router.Post(webClientLoginPath, s.handleWebClientLoginPost)
|
||||
|
|
Loading…
Reference in a new issue