Commit 3409ce39 authored by Dmitri Shuralyov's avatar Dmitri Shuralyov

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/+/202482Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: default avatarRobert Griesemer <gri@golang.org>
parent d24cf6d5
......@@ -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
}
......
......@@ -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;",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment