From 72bf216cb47504309e37f05ee94469e9073516ae Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Mon, 2 Dec 2013 18:20:11 -0800 Subject: [PATCH] fix(server/v2): redirect to ClientURL not PeerURL If consistent is set you must redirect the client to the leader's ClientURL not the PeerURL. --- server/server.go | 5 +++++ server/v2/get_handler.go | 2 +- server/v2/v2.go | 1 + tests/mock/server_v2.go | 5 +++++ 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/server/server.go b/server/server.go index 4f75df2e0..00c39227a 100644 --- a/server/server.go +++ b/server/server.go @@ -96,6 +96,11 @@ func (s *Server) PeerURL(name string) (string, bool) { return s.registry.PeerURL(name) } +// ClientURL retrieves the Client URL for a given node name. +func (s *Server) ClientURL(name string) (string, bool) { + return s.registry.ClientURL(name) +} + // Returns a reference to the Store. func (s *Server) Store() store.Store { return s.store diff --git a/server/v2/get_handler.go b/server/v2/get_handler.go index dd0bdc180..2f48fc32a 100644 --- a/server/v2/get_handler.go +++ b/server/v2/get_handler.go @@ -23,7 +23,7 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error { // Help client to redirect the request to the current leader if req.FormValue("consistent") == "true" && s.State() != raft.Leader { leader := s.Leader() - hostname, _ := s.PeerURL(leader) + hostname, _ := s.ClientURL(leader) url := hostname + req.URL.Path log.Debugf("Redirect consistent get to %s", url) http.Redirect(w, req, url, http.StatusTemporaryRedirect) diff --git a/server/v2/v2.go b/server/v2/v2.go index 135479d29..0cdfb1cf7 100644 --- a/server/v2/v2.go +++ b/server/v2/v2.go @@ -13,6 +13,7 @@ type Server interface { CommitIndex() uint64 Term() uint64 PeerURL(string) (string, bool) + ClientURL(string) (string, bool) Store() store.Store Dispatch(raft.Command, http.ResponseWriter, *http.Request) error } diff --git a/tests/mock/server_v2.go b/tests/mock/server_v2.go index d48d5c0ef..a4e8821a1 100644 --- a/tests/mock/server_v2.go +++ b/tests/mock/server_v2.go @@ -45,6 +45,11 @@ func (s *ServerV2) PeerURL(name string) (string, bool) { return args.String(0), args.Bool(1) } +func (s *ServerV2) ClientURL(name string) (string, bool) { + args := s.Called(name) + return args.String(0), args.Bool(1) +} + func (s *ServerV2) Store() store.Store { return s.store }