mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
use net/url pacakge
This commit is contained in:
parent
61f238f22e
commit
5767b4e245
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
|
|
||||||
"github.com/coreos/etcd/log"
|
"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) {
|
func redirect(hostname string, w http.ResponseWriter, req *http.Request) {
|
||||||
path := req.URL.Path
|
originalURL, _ := url.Parse(req.URL.String())
|
||||||
query := req.URL.RawQuery
|
redirectURL, _ := url.Parse(hostname)
|
||||||
url := hostname + path + "?" + query
|
|
||||||
log.Debugf("Redirect to %s", url)
|
// we need the original path and raw query
|
||||||
http.Redirect(w, req, url, http.StatusTemporaryRedirect)
|
redirectURL.Path = originalURL.Path
|
||||||
|
redirectURL.RawQuery = originalURL.RawQuery
|
||||||
|
|
||||||
|
log.Debugf("Redirect to %s", redirectURL.String())
|
||||||
|
http.Redirect(w, req, redirectURL.String(), http.StatusTemporaryRedirect)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user