Skip to content

Commit

Permalink
Merge pull request #363 from xiangli-cmu/fix_consistent_redirection
Browse files Browse the repository at this point in the history
fix redirect url should include rawquery
  • Loading branch information
xiang90 committed Dec 6, 2013
2 parents 1a7eb36 + ded3cc2 commit 5edaee7
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions server/v2/get_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"

etcdErr "github.com/coreos/etcd/error"
Expand All @@ -24,9 +25,17 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {
if req.FormValue("consistent") == "true" && s.State() != raft.Leader {
leader := s.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
}

Expand Down

0 comments on commit 5edaee7

Please sign in to comment.