1
0
mirror of https://github.com/golang/go synced 2024-11-18 15:04:44 -07:00

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:
Burcu Dogan 2015-10-05 20:00:21 -07:00 committed by Andrew Gerrand
parent 365aedefa0
commit f247eeaee6
2 changed files with 14 additions and 8 deletions

View File

@ -142,7 +142,11 @@ var prefixHelpers = map[string]string{
func Handler(target string) http.Handler {
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)
})
}

View File

@ -41,10 +41,12 @@ func TestRedirects(t *testing.T) {
"/change/a": {302, "https://go.googlesource.com/go/+/a"},
"/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"},
"/issues/1": {302, "https://github.com/golang/go/issues/1"},
"/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/1/2/3": errorResult(404),