diff --git a/src/net/http/server.go b/src/net/http/server.go index 2fa8ab23d8..d370be9ecd 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -2013,13 +2013,17 @@ func Redirect(w ResponseWriter, r *Request, url string, code int) { } } - w.Header().Set("Location", hexEscapeNonASCII(url)) - w.WriteHeader(code) - // RFC 2616 recommends that a short note "SHOULD" be included in the // response because older user agents may not understand 301/307. // Shouldn't send the response for POST or HEAD; that leaves GET. - if r.Method == "GET" { + writeNote := r.Method == "GET" + + w.Header().Set("Location", hexEscapeNonASCII(url)) + if writeNote { + w.Header().Set("Content-Type", "text/html; charset=utf-8") + } + w.WriteHeader(code) + if writeNote { note := "" + statusText[code] + ".\n" fmt.Fprintln(w, note) }