diff --git a/CHANGELOG.md b/CHANGELOG.md index edcbc143..21176b09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 6.6.6 (unreleased) +### Implementation changes and bug fixes +- [PR #917](https://github.com/rqlite/rqlite/pull/917): Redirect HTTP `/` to `/status`. + ## 6.6.5 (October 21st 2021) ### Implementation changes and bug fixes - [PR #916](https://github.com/rqlite/rqlite/pull/916): More helpful log messages on start-up. diff --git a/http/service.go b/http/service.go index d2818ef2..80003d99 100644 --- a/http/service.go +++ b/http/service.go @@ -302,6 +302,8 @@ func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request) { } switch { + case r.URL.Path == "/" || r.URL.Path == "": + http.Redirect(w, r, "/status", http.StatusFound) case strings.HasPrefix(r.URL.Path, "/db/execute"): stats.Add(numExecutions, 1) s.handleExecute(w, r) diff --git a/http/service_test.go b/http/service_test.go index bc93a116..b2fe14b3 100644 --- a/http/service_test.go +++ b/http/service_test.go @@ -684,6 +684,43 @@ func Test_Nodes(t *testing.T) { } } +func Test_RootRedirectToStatus(t *testing.T) { + m := &MockStore{} + c := &mockClusterService{} + s := New("127.0.0.1:0", m, c, nil) + if err := s.Start(); err != nil { + t.Fatalf("failed to start service") + } + defer s.Close() + + client := &http.Client{ + CheckRedirect: func(req *http.Request, via []*http.Request) error { + return http.ErrUseLastResponse + }, + } + resp, err := client.Get(fmt.Sprintf("http://%s/", s.Addr().String())) + if err != nil { + t.Fatalf("failed to make root request") + } + if resp.StatusCode != http.StatusFound { + t.Fatalf("failed to get expected StatusFound for root, got %d", resp.StatusCode) + } + if resp.Header["Location"][0] != "/status" { + t.Fatalf("received incorrect redirect path") + } + + resp, err = client.Get(fmt.Sprintf("http://%s", s.Addr().String())) + if err != nil { + t.Fatalf("failed to make root request") + } + if resp.StatusCode != http.StatusFound { + t.Fatalf("failed to get expected StatusFound for root, got %d", resp.StatusCode) + } + if resp.Header["Location"][0] != "/status" { + t.Fatalf("received incorrect redirect path") + } +} + func Test_Readyz(t *testing.T) { m := &MockStore{ leaderAddr: "foo:1234",