From 5767b4e2455b4195b8b70986498ea0e43a02e46c Mon Sep 17 00:00:00 2001 From: Xiang Li Date: Sun, 20 Oct 2013 11:10:24 -0700 Subject: [PATCH] use net/url pacakge --- server/util.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server/util.go b/server/util.go index baa7c2845..7c992e873 100644 --- a/server/util.go +++ b/server/util.go @@ -5,6 +5,7 @@ import ( "fmt" "io" "net/http" + "net/url" "github.com/coreos/etcd/log" ) @@ -19,9 +20,13 @@ func decodeJsonRequest(req *http.Request, data interface{}) error { } func redirect(hostname string, w http.ResponseWriter, req *http.Request) { - path := req.URL.Path - query := req.URL.RawQuery - url := hostname + path + "?" + query - log.Debugf("Redirect to %s", url) - http.Redirect(w, req, url, http.StatusTemporaryRedirect) + originalURL, _ := url.Parse(req.URL.String()) + redirectURL, _ := url.Parse(hostname) + + // we need the original path and raw query + redirectURL.Path = originalURL.Path + redirectURL.RawQuery = originalURL.RawQuery + + log.Debugf("Redirect to %s", redirectURL.String()) + http.Redirect(w, req, redirectURL.String(), http.StatusTemporaryRedirect) }