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 коммит произвёл Andrew Gerrand
Родитель 365aedefa0
Коммит f247eeaee6
2 изменённых файлов: 14 добавлений и 8 удалений

Просмотреть файл

@ -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)
}) })
} }

Просмотреть файл

@ -40,13 +40,15 @@ func TestRedirects(t *testing.T) {
"/change": {301, "https://go.googlesource.com/go"}, "/change": {301, "https://go.googlesource.com/go"},
"/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/new": {301, "https://github.com/golang/go/issues/new"}, "/issues": {301, "https://github.com/golang/go/issues"},
"/issues/1/2/3": errorResult(404), "/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),
"/design": {301, "https://github.com/golang/proposal/tree/master/design"}, "/design": {301, "https://github.com/golang/proposal/tree/master/design"},
"/design/": {302, "/design"}, "/design/": {302, "/design"},