]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: extra documentation for Redirect and RedirectHandler
authorTaru Karttunen <taruti@taruti.net>
Fri, 16 Oct 2015 10:26:20 +0000 (13:26 +0300)
committerBrad Fitzpatrick <bradfitz@golang.org>
Thu, 29 Oct 2015 19:52:45 +0000 (19:52 +0000)
Errors with http.Redirect and http.StatusOk seem
to occur from time to time on the irc channel.
This change adds documentation suggesting
to use one of the 3xx codes and not StatusOk
with Redirect.

Change-Id: I6b900a8eb868265fbbb846ee6a53e426d90a727d
Reviewed-on: https://go-review.googlesource.com/15980
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/net/http/server.go

index a2245fe6bfc956c9a67ced3bd1c8c14d578c13d4..e8470efd6bde856fb51b285ba91315b82e0c15f4 100644 (file)
@@ -1472,6 +1472,9 @@ func StripPrefix(prefix string, h Handler) Handler {
 
 // Redirect replies to the request with a redirect to url,
 // which may be a path relative to the request path.
+//
+// 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) {
        if u, err := url.Parse(urlStr); err == nil {
                // If url was relative, make absolute by
@@ -1556,6 +1559,9 @@ func (rh *redirectHandler) ServeHTTP(w ResponseWriter, r *Request) {
 // RedirectHandler returns a request handler that redirects
 // each request it receives to the given url using the given
 // status code.
+//
+// The provided code should be in the 3xx range and is usually
+// StatusMovedPermanently, StatusFound or StatusSeeOther.
 func RedirectHandler(url string, code int) Handler {
        return &redirectHandler{url, code}
 }