Skip to content

Commit ded3cc2

Browse files
committed
fix redirect url should include rawquery
1 parent c6e1af8 commit ded3cc2

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

server/v2/get_handler.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"net/http"
7+
"net/url"
78
"strconv"
89

910
etcdErr "github.com/coreos/etcd/error"
@@ -24,9 +25,17 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {
2425
if req.FormValue("consistent") == "true" && s.State() != raft.Leader {
2526
leader := s.Leader()
2627
hostname, _ := s.ClientURL(leader)
27-
url := hostname + req.URL.Path
28-
log.Debugf("Redirect consistent get to %s", url)
29-
http.Redirect(w, req, url, http.StatusTemporaryRedirect)
28+
29+
url, err := url.Parse(hostname)
30+
if err != nil {
31+
log.Warn("Redirect cannot parse hostName ", hostname)
32+
return err
33+
}
34+
url.RawQuery = req.URL.RawQuery
35+
url.Path = req.URL.Path
36+
37+
log.Debugf("Redirect consistent get to %s", url.String())
38+
http.Redirect(w, req, url.String(), http.StatusTemporaryRedirect)
3039
return nil
3140
}
3241

0 commit comments

Comments
 (0)