mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
fix redirect url should include rawquery
This commit is contained in:
parent
c6e1af8321
commit
ded3cc24c0
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
etcdErr "github.com/coreos/etcd/error"
|
etcdErr "github.com/coreos/etcd/error"
|
||||||
@ -24,9 +25,17 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {
|
|||||||
if req.FormValue("consistent") == "true" && s.State() != raft.Leader {
|
if req.FormValue("consistent") == "true" && s.State() != raft.Leader {
|
||||||
leader := s.Leader()
|
leader := s.Leader()
|
||||||
hostname, _ := s.ClientURL(leader)
|
hostname, _ := s.ClientURL(leader)
|
||||||
url := hostname + req.URL.Path
|
|
||||||
log.Debugf("Redirect consistent get to %s", url)
|
url, err := url.Parse(hostname)
|
||||||
http.Redirect(w, req, url, http.StatusTemporaryRedirect)
|
if err != nil {
|
||||||
|
log.Warn("Redirect cannot parse hostName ", hostname)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
url.RawQuery = req.URL.RawQuery
|
||||||
|
url.Path = req.URL.Path
|
||||||
|
|
||||||
|
log.Debugf("Redirect consistent get to %s", url.String())
|
||||||
|
http.Redirect(w, req, url.String(), http.StatusTemporaryRedirect)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user