mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
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.
This commit is contained in:
parent
cfb6eb6e50
commit
72bf216cb4
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user