Skip to content

Commit 86c2ab5

Browse files
committed
internal/proxy: remove URL validation in New
Rather than validating the URL in proxy.New, assume that the URL that is passed in is valid. This allows users to connect to a proxy running locally in direct proxy mode. For golang/go#40371 Change-Id: Id51cb27148987e58d214cef1c805b26b5138a6de Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/245639 Run-TryBot: Julie Qiu <[email protected]> TryBot-Result: kokoro <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]>
1 parent a956e7c commit 86c2ab5

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

internal/proxy/client.go

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"io"
1616
"io/ioutil"
1717
"net/http"
18-
"net/url"
1918
"strings"
2019
"time"
2120

@@ -42,19 +41,14 @@ type VersionInfo struct {
4241
Time time.Time
4342
}
4443

45-
// New constructs a *Client using the provided rawurl, which is expected to
44+
// New constructs a *Client using the provided url, which is expected to
4645
// be an absolute URI that can be directly passed to http.Get.
47-
func New(rawurl string) (_ *Client, err error) {
48-
defer derrors.Wrap(&err, "proxy.New(%q)", rawurl)
49-
url, err := url.Parse(rawurl)
50-
if err != nil {
51-
return nil, fmt.Errorf("url.Parse: %v", err)
52-
}
53-
if url.Scheme != "https" {
54-
return nil, fmt.Errorf("scheme must be https (got %s)", url.Scheme)
55-
}
56-
cleanURL := strings.TrimRight(rawurl, "/")
57-
return &Client{url: cleanURL, httpClient: &http.Client{Transport: &ochttp.Transport{}}}, nil
46+
func New(u string) (_ *Client, err error) {
47+
defer derrors.Wrap(&err, "proxy.New(%q)", u)
48+
return &Client{
49+
url: strings.TrimRight(u, "/"),
50+
httpClient: &http.Client{Transport: &ochttp.Transport{}},
51+
}, nil
5852
}
5953

6054
// GetInfo makes a request to $GOPROXY/<module>/@v/<requestedVersion>.info and

0 commit comments

Comments
 (0)