Skip to content

Commit

Permalink
internal/proxy: remove URL validation in New
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
julieqiu committed Jul 29, 2020
1 parent a956e7c commit 86c2ab5
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions internal/proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"

Expand All @@ -42,19 +41,14 @@ type VersionInfo struct {
Time time.Time
}

// New constructs a *Client using the provided rawurl, which is expected to
// New constructs a *Client using the provided url, which is expected to
// be an absolute URI that can be directly passed to http.Get.
func New(rawurl string) (_ *Client, err error) {
defer derrors.Wrap(&err, "proxy.New(%q)", rawurl)
url, err := url.Parse(rawurl)
if err != nil {
return nil, fmt.Errorf("url.Parse: %v", err)
}
if url.Scheme != "https" {
return nil, fmt.Errorf("scheme must be https (got %s)", url.Scheme)
}
cleanURL := strings.TrimRight(rawurl, "/")
return &Client{url: cleanURL, httpClient: &http.Client{Transport: &ochttp.Transport{}}}, nil
func New(u string) (_ *Client, err error) {
defer derrors.Wrap(&err, "proxy.New(%q)", u)
return &Client{
url: strings.TrimRight(u, "/"),
httpClient: &http.Client{Transport: &ochttp.Transport{}},
}, nil
}

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

0 comments on commit 86c2ab5

Please sign in to comment.