aboutsummaryrefslogtreecommitdiff
path: root/src/net/http/server.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/http/server.go')
-rw-r--r--src/net/http/server.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/net/http/server.go b/src/net/http/server.go
index 45f8e1b16a..71f46a74f9 100644
--- a/src/net/http/server.go
+++ b/src/net/http/server.go
@@ -1963,6 +1963,7 @@ func StripPrefix(prefix string, h Handler) Handler {
// The provided code should be in the 3xx range and is usually
// StatusMovedPermanently, StatusFound or StatusSeeOther.
func Redirect(w ResponseWriter, r *Request, urlStr string, code int) {
+ queryAlreadySet := false
if u, err := url.Parse(urlStr); err == nil {
// If url was relative, make absolute by
// combining with request path.
@@ -2005,9 +2006,17 @@ func Redirect(w ResponseWriter, r *Request, urlStr string, code int) {
urlStr += "/"
}
urlStr += query
+ queryAlreadySet = len(query) != 0
}
}
+ // We should make sure not to lose the query string of
+ // the original request when doing a redirect, if not already set.
+ // See Issue 17841.
+ if !queryAlreadySet && len(r.URL.RawQuery) != 0 {
+ urlStr += "?" + r.URL.RawQuery
+ }
+
w.Header().Set("Location", hexEscapeNonASCII(urlStr))
w.WriteHeader(code)