зеркало из https://github.com/golang/tools.git
godoc: don't drop the query params when redirecting
http://golang.org/issue/new?title=Title was being redirected to https://github.com/golang/go/issues/new. The CL preserves the query parameters during direct. Change-Id: I3057ccd5304b00df53b664b71ea35ea05d313aa4 Reviewed-on: https://go-review.googlesource.com/15431 Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
Родитель
365aedefa0
Коммит
f247eeaee6
|
@ -142,7 +142,11 @@ var prefixHelpers = map[string]string{
|
||||||
|
|
||||||
func Handler(target string) http.Handler {
|
func Handler(target string) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
http.Redirect(w, r, target, http.StatusMovedPermanently)
|
url := target
|
||||||
|
if qs := r.URL.RawQuery; qs != "" {
|
||||||
|
url += "?" + qs
|
||||||
|
}
|
||||||
|
http.Redirect(w, r, url, http.StatusMovedPermanently)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,10 +41,12 @@ func TestRedirects(t *testing.T) {
|
||||||
"/change/a": {302, "https://go.googlesource.com/go/+/a"},
|
"/change/a": {302, "https://go.googlesource.com/go/+/a"},
|
||||||
|
|
||||||
"/issue": {301, "https://github.com/golang/go/issues"},
|
"/issue": {301, "https://github.com/golang/go/issues"},
|
||||||
"/issues": {301, "https://github.com/golang/go/issues"},
|
"/issue?": {301, "https://github.com/golang/go/issues"},
|
||||||
"/issue/1": {302, "https://github.com/golang/go/issues/1"},
|
"/issue/1": {302, "https://github.com/golang/go/issues/1"},
|
||||||
"/issues/1": {302, "https://github.com/golang/go/issues/1"},
|
|
||||||
"/issue/new": {301, "https://github.com/golang/go/issues/new"},
|
"/issue/new": {301, "https://github.com/golang/go/issues/new"},
|
||||||
|
"/issue/new?a=b&c=d%20&e=f": {301, "https://github.com/golang/go/issues/new?a=b&c=d%20&e=f"},
|
||||||
|
"/issues": {301, "https://github.com/golang/go/issues"},
|
||||||
|
"/issues/1": {302, "https://github.com/golang/go/issues/1"},
|
||||||
"/issues/new": {301, "https://github.com/golang/go/issues/new"},
|
"/issues/new": {301, "https://github.com/golang/go/issues/new"},
|
||||||
"/issues/1/2/3": errorResult(404),
|
"/issues/1/2/3": errorResult(404),
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче