]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: remove parseURL variable
authorDmitri Shuralyov <dmitshur@golang.org>
Mon, 21 Oct 2019 19:30:13 +0000 (15:30 -0400)
committerDmitri Shuralyov <dmitshur@golang.org>
Mon, 21 Oct 2019 20:43:40 +0000 (20:43 +0000)
The parseURL variable was introduced in CL 49930 in order to work
around the fact that the name "url" was shadowed by a parameter of
exported functions, and couldn't be renamed without sacrificing
documentation readability. Documentation readability takes higher
priority than internal implementation details.

Back then, I considered renaming the net/url import but saw that it
would be too disruptive of a change to the large net/http package.

Now I see a better way: it's possible to import net/url both as url
and as urlpkg (the package is still imported just once, but it becomes
available via two names). This way we eliminate the need for wasting
(a little) memory on the parseURL variable, improve code readability
slightly, and delete some lines of code and comments.

Updates #21077

Change-Id: I42cd9833afdcf4a5f5874fb7ee9c8c11eae557dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/202482
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/net/http/request.go
src/net/http/server.go

index 1fdd8a4fc7055c16861019931089cdc4a2c0a2aa..72261a1bd5ed9026351aa655d89da3182bfa5655 100644 (file)
@@ -22,6 +22,7 @@ import (
        "net/http/httptrace"
        "net/textproto"
        "net/url"
+       urlpkg "net/url"
        "strconv"
        "strings"
        "sync"
@@ -850,7 +851,7 @@ func NewRequestWithContext(ctx context.Context, method, url string, body io.Read
        if ctx == nil {
                return nil, errors.New("net/http: nil Context")
        }
-       u, err := parseURL(url) // Just url.Parse (url is shadowed for godoc).
+       u, err := urlpkg.Parse(url)
        if err != nil {
                return nil, err
        }
index f87e339dde72fa17098c3e5077a918684a522559..ff93e59bc06dd62e6e8e804037afb561ef9d2ae7 100644 (file)
@@ -19,6 +19,7 @@ import (
        "net"
        "net/textproto"
        "net/url"
+       urlpkg "net/url"
        "os"
        "path"
        "runtime"
@@ -2065,8 +2066,7 @@ func StripPrefix(prefix string, h Handler) Handler {
 // Setting the Content-Type header to any value, including nil,
 // disables that behavior.
 func Redirect(w ResponseWriter, r *Request, url string, code int) {
-       // parseURL is just url.Parse (url is shadowed for godoc).
-       if u, err := parseURL(url); err == nil {
+       if u, err := urlpkg.Parse(url); err == nil {
                // If url was relative, make its path absolute by
                // combining with request path.
                // The client would probably do this for us,
@@ -2120,10 +2120,6 @@ func Redirect(w ResponseWriter, r *Request, url string, code int) {
        }
 }
 
-// parseURL is just url.Parse. It exists only so that url.Parse can be called
-// in places where url is shadowed for godoc. See https://golang.org/cl/49930.
-var parseURL = url.Parse
-
 var htmlReplacer = strings.NewReplacer(
        "&", "&amp;",
        "<", "&lt;",