redirect join to server port

This commit is contained in:
Xiang Li
2013-07-10 20:00:05 -07:00
parent 8af746ef6d
commit 45af72c941
3 changed files with 28 additions and 12 deletions

View File

@ -51,7 +51,7 @@ func SetHttpHandler(w *http.ResponseWriter, req *http.Request) {
(*w).WriteHeader(http.StatusInternalServerError)
}
dispatch(command, w, req)
dispatch(command, w, req, true)
}
@ -77,7 +77,7 @@ func TestAndSetHttpHandler(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
}
dispatch(command, &w, req)
dispatch(command, &w, req, true)
}
@ -90,11 +90,11 @@ func DeleteHttpHandler(w *http.ResponseWriter, req *http.Request) {
command := &DeleteCommand{}
command.Key = key
dispatch(command, w, req)
dispatch(command, w, req, true)
}
// Dispatch the command to leader
func dispatch(c Command, w *http.ResponseWriter, req *http.Request) {
func dispatch(c Command, w *http.ResponseWriter, req *http.Request, client bool) {
if raftServer.State() == "leader" {
if body, err := raftServer.Do(c); err != nil {
warn("Commit failed %v", err)
@ -132,7 +132,13 @@ func dispatch(c Command, w *http.ResponseWriter, req *http.Request) {
scheme = "http://"
}
url := scheme + raftTransporter.GetLeaderClientAddress() + path
var url string
if client {
url = scheme + raftTransporter.GetLeaderClientAddress() + path
} else {
url = scheme + raftServer.Leader() + path
}
debug("Redirect to %s", url)