Browse Source

change response HTTP header to StatusServiceUnavailable when the server is not leader

Xiang Li 12 years ago
parent
commit
1228694383
2 changed files with 3 additions and 2 deletions
  1. 2 1
      handlers.go
  2. 1 1
      raftd.go

+ 2 - 1
handlers.go

@@ -144,7 +144,8 @@ func excute(c Command, w *http.ResponseWriter) {
 		}
 		}
 	} else {
 	} else {
 		// tell the client where is the leader
 		// tell the client where is the leader
-		(*w).WriteHeader(http.StatusTemporaryRedirect)
+		debug("Redirect to the leader %s",  server.Leader())
+		(*w).WriteHeader(http.StatusServiceUnavailable)
 		(*w).Write([]byte(server.Leader()))
 		(*w).Write([]byte(server.Leader()))
 		return
 		return
 	}
 	}

+ 1 - 1
raftd.go

@@ -379,7 +379,7 @@ func Join(s *raft.Server, serverName string) error {
 			if resp.StatusCode == http.StatusOK {
 			if resp.StatusCode == http.StatusOK {
 				return nil
 				return nil
 			}
 			}
-			if resp.StatusCode == http.StatusTemporaryRedirect {
+			if resp.StatusCode == http.StatusServiceUnavailable {
 				address, err := ioutil.ReadAll(resp.Body)
 				address, err := ioutil.ReadAll(resp.Body)
 				if err != nil {
 				if err != nil {
 					warn("Cannot Read Leader info: %v", err)
 					warn("Cannot Read Leader info: %v", err)