Browse Source

Merge pull request #363 from xiangli-cmu/fix_consistent_redirection

fix redirect url should include rawquery
Xiang Li 12 years ago
parent
commit
5edaee79e6
1 changed files with 12 additions and 3 deletions
  1. 12 3
      server/v2/get_handler.go

+ 12 - 3
server/v2/get_handler.go

@@ -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)
-		http.Redirect(w, req, url, http.StatusTemporaryRedirect)
+
+		url, err := url.Parse(hostname)
+		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
 	}
 	}