Skip to content

Commit 3409ce3

Browse files
committed
net/http: remove parseURL variable
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>
1 parent d24cf6d commit 3409ce3

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

src/net/http/request.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"net/http/httptrace"
2323
"net/textproto"
2424
"net/url"
25+
urlpkg "net/url"
2526
"strconv"
2627
"strings"
2728
"sync"
@@ -850,7 +851,7 @@ func NewRequestWithContext(ctx context.Context, method, url string, body io.Read
850851
if ctx == nil {
851852
return nil, errors.New("net/http: nil Context")
852853
}
853-
u, err := parseURL(url) // Just url.Parse (url is shadowed for godoc).
854+
u, err := urlpkg.Parse(url)
854855
if err != nil {
855856
return nil, err
856857
}

src/net/http/server.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"net"
2020
"net/textproto"
2121
"net/url"
22+
urlpkg "net/url"
2223
"os"
2324
"path"
2425
"runtime"
@@ -2065,8 +2066,7 @@ func StripPrefix(prefix string, h Handler) Handler {
20652066
// Setting the Content-Type header to any value, including nil,
20662067
// disables that behavior.
20672068
func Redirect(w ResponseWriter, r *Request, url string, code int) {
2068-
// parseURL is just url.Parse (url is shadowed for godoc).
2069-
if u, err := parseURL(url); err == nil {
2069+
if u, err := urlpkg.Parse(url); err == nil {
20702070
// If url was relative, make its path absolute by
20712071
// combining with request path.
20722072
// The client would probably do this for us,
@@ -2120,10 +2120,6 @@ func Redirect(w ResponseWriter, r *Request, url string, code int) {
21202120
}
21212121
}
21222122

2123-
// parseURL is just url.Parse. It exists only so that url.Parse can be called
2124-
// in places where url is shadowed for godoc. See https://golang.org/cl/49930.
2125-
var parseURL = url.Parse
2126-
21272123
var htmlReplacer = strings.NewReplacer(
21282124
"&", "&amp;",
21292125
"<", "&lt;",

0 commit comments

Comments
 (0)