From f247eeaee6978cdf4dc9e13150953c8550c0a428 Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Mon, 5 Oct 2015 20:00:21 -0700 Subject: [PATCH] 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 --- godoc/redirect/redirect.go | 6 +++++- godoc/redirect/redirect_test.go | 16 +++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/godoc/redirect/redirect.go b/godoc/redirect/redirect.go index 54fc578e..b07d97f1 100644 --- a/godoc/redirect/redirect.go +++ b/godoc/redirect/redirect.go @@ -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) }) } diff --git a/godoc/redirect/redirect_test.go b/godoc/redirect/redirect_test.go index 5fc6c1f5..5e8045a3 100644 --- a/godoc/redirect/redirect_test.go +++ b/godoc/redirect/redirect_test.go @@ -40,13 +40,15 @@ func TestRedirects(t *testing.T) { "/change": {301, "https://go.googlesource.com/go"}, "/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/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"}, - "/issues/new": {301, "https://github.com/golang/go/issues/new"}, - "/issues/1/2/3": errorResult(404), + "/issue": {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/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), "/design": {301, "https://github.com/golang/proposal/tree/master/design"}, "/design/": {302, "/design"},