Commit bdd42015 authored by Bryan C. Mills's avatar Bryan C. Mills

cmd/go: allow GOPROXY to elide the "https://" prefix

Fixes #32191

Change-Id: I6eebe1d4975e904c906e6b839cd6cab9447cbb34
Reviewed-on: https://go-review.googlesource.com/c/go/+/181019
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarRuss Cox <rsc@golang.org>
parent d36452eb
...@@ -12,7 +12,9 @@ import ( ...@@ -12,7 +12,9 @@ import (
"io/ioutil" "io/ioutil"
"net/url" "net/url"
"os" "os"
"path"
pathpkg "path" pathpkg "path"
"path/filepath"
"strings" "strings"
"sync" "sync"
"time" "time"
...@@ -110,6 +112,13 @@ func proxyURLs() ([]string, error) { ...@@ -110,6 +112,13 @@ func proxyURLs() ([]string, error) {
break break
} }
// Single-word tokens are reserved for built-in behaviors, and anything
// containing the string ":/" or matching an absolute file path must be a
// complete URL. For all other paths, implicitly add "https://".
if strings.ContainsAny(proxyURL, ".:/") && !strings.Contains(proxyURL, ":/") && !filepath.IsAbs(proxyURL) && !path.IsAbs(proxyURL) {
proxyURL = "https://" + proxyURL
}
// Check that newProxyRepo accepts the URL. // Check that newProxyRepo accepts the URL.
// It won't do anything with the path. // It won't do anything with the path.
_, err := newProxyRepo(proxyURL, "golang.org/x/text") _, err := newProxyRepo(proxyURL, "golang.org/x/text")
......
...@@ -145,7 +145,7 @@ func (c *dbClient) initBase() { ...@@ -145,7 +145,7 @@ func (c *dbClient) initBase() {
if proxyURL == "noproxy" { if proxyURL == "noproxy" {
continue continue
} }
if proxyURL == "direct" { if proxyURL == "direct" || proxyURL == "off" {
break break
} }
proxy, err := url.Parse(proxyURL) proxy, err := url.Parse(proxyURL)
......
env GO111MODULE=on
# GOPROXY file paths must provide the "file://" prefix explicitly.
env GOPROXY=$WORK/proxydir
! go list -versions -m golang.org/x/text
stderr 'invalid proxy URL.*proxydir'
[!net] stop
# GOPROXY HTTPS paths may elide the "https://" prefix.
# (See golang.org/issue/32191.)
env GOPROXY=proxy.golang.org
go list -versions -m golang.org/x/text
-- go.mod --
module example.com
go 1.13
-- $WORK/proxydir/README.md --
This proxy contains no data.
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