import (
"crypto/tls"
"fmt"
- "log"
+ "io/ioutil"
"net/http"
urlpkg "net/url"
+ "os"
+ "strings"
"time"
"cmd/go/internal/auth"
}
func get(security SecurityMode, url *urlpkg.URL) (*Response, error) {
+ start := time.Now()
+ if os.Getenv("TESTGOPROXY404") == "1" && url.Host == "proxy.golang.org" {
+ res := &Response{
+ URL: Redacted(url),
+ Status: "404 testing",
+ StatusCode: 404,
+ Header: make(map[string][]string),
+ Body: ioutil.NopCloser(strings.NewReader("")),
+ }
+ if cfg.BuildX {
+ fmt.Fprintf(os.Stderr, "# get %s: %v (%.3fs)\n", Redacted(url), res.Status, time.Since(start).Seconds())
+ }
+ return res, nil
+ }
+
fetch := func(url *urlpkg.URL) (*urlpkg.URL, *http.Response, error) {
- if cfg.BuildV {
- log.Printf("Fetching %s", url)
+ // Note: The -v build flag does not mean "print logging information",
+ // despite its historical misuse for this in GOPATH-based go get.
+ // We print extra logging in -x mode instead, which traces what
+ // commands are executed.
+ if cfg.BuildX {
+ fmt.Fprintf(os.Stderr, "# get %s\n", Redacted(url))
}
req, err := http.NewRequest("GET", url.String(), nil)
fetched, res, err = fetch(secure)
if err != nil {
- if cfg.BuildV {
- log.Printf("https fetch failed: %v", err)
+ if cfg.BuildX {
+ fmt.Fprintf(os.Stderr, "# get %s: %v\n", Redacted(url), err)
}
if security != Insecure || url.Scheme == "https" {
// HTTPS failed, and we can't fall back to plain HTTP.
switch url.Scheme {
case "http":
if security == SecureOnly {
+ if cfg.BuildX {
+ fmt.Fprintf(os.Stderr, "# get %s: insecure\n", Redacted(url))
+ }
return nil, fmt.Errorf("insecure URL: %s", Redacted(url))
}
case "":
panic("should have returned after HTTPS failure")
}
default:
+ if cfg.BuildX {
+ fmt.Fprintf(os.Stderr, "# get %s: unsupported\n", Redacted(url))
+ }
return nil, fmt.Errorf("unsupported scheme: %s", Redacted(url))
}
*insecure = *url
insecure.Scheme = "http"
if insecure.User != nil && security != Insecure {
+ if cfg.BuildX {
+ fmt.Fprintf(os.Stderr, "# get %s: insecure credentials\n", Redacted(url))
+ }
return nil, fmt.Errorf("refusing to pass credentials to insecure URL: %s", Redacted(insecure))
}
fetched, res, err = fetch(insecure)
if err != nil {
+ if cfg.BuildX {
+ fmt.Fprintf(os.Stderr, "# get %s: %v\n", Redacted(url), err)
+ }
// HTTP failed, and we already tried HTTPS if applicable.
// Report the error from the HTTP attempt.
return nil, err
// Note: accepting a non-200 OK here, so people can serve a
// meta import in their http 404 page.
- if cfg.BuildV {
- log.Printf("reading from %s: status code %d", Redacted(fetched), res.StatusCode)
+ if cfg.BuildX {
+ fmt.Fprintf(os.Stderr, "# get %s: %v (%.3fs)\n", Redacted(url), res.Status, time.Since(start).Seconds())
}
r := &Response{
URL: Redacted(fetched),
env GOPROXY=
env GOSUMDB=
go env GOPROXY
-stdout '^https://proxy.golang.org$'
+stdout '^https://proxy.golang.org,direct$'
go env GOSUMDB
stdout '^sum.golang.org$'
env GOPROXY=https://proxy.golang.org
env GOPROXY=direct
go get -m rsc.io/quote
-# download from proxy.golang.org
+# download from proxy.golang.org with go.sum entry already
go clean -modcache
-env GOSUMDB='sum.golang.org https://sum.golang.org' # TODO remove URL
-env GOPROXY=https://proxy.golang.org
-go get -m rsc.io/quote
+env GOSUMDB=
+env GOPROXY=
+go get -x -m rsc.io/quote
+! stderr github
+stderr proxy.golang.org/rsc.io/quote
+! stderr sum.golang.org/tile
+! stderr sum.golang.org/lookup/rsc.io/quote
+
+# download again, using checksum database to validate new go.sum lines
+rm go.sum
+go get -x -m rsc.io/quote
+! stderr github
+stderr proxy.golang.org/rsc.io/quote
+stderr sum.golang.org/tile
+stderr sum.golang.org/lookup/rsc.io/quote
+
+# test fallback to direct
+env TESTGOPROXY404=1
+go get -x -m rsc.io/quote
+stderr 'proxy.golang.org.*404 testing'
+stderr github.com/rsc
-- go.mod --
module m