1
0
Fork 0

Merge pull request #917 from rqlite/redirect-root-to-status

Redirect root to status
master
Philip O'Toole 3 years ago committed by GitHub
commit 53ac29d190
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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.

@ -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)

@ -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",

Loading…
Cancel
Save