cmd/go: initialize req.Header when loading git credential

Fixes #71604

Change-Id: I3d733a50b4451dfb571aba91a28387ba9e0614dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/647615
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
This commit is contained in:
Quan Tong 2025-02-07 18:42:26 +07:00 committed by Sam Thanawalla
parent b574590c36
commit 58834c3ee0
2 changed files with 4 additions and 1 deletions

View File

@ -128,7 +128,8 @@ func runGoAuth(client *http.Client, res *http.Response, url string) {
// If no GOAUTH command provided a credential for the given url
// and an error occurred, log the error.
if cfg.BuildX && url != "" {
if ok := loadCredential(&http.Request{}, url); !ok && len(cmdErrs) > 0 {
req := &http.Request{Header: make(http.Header)}
if ok := loadCredential(req, url); !ok && len(cmdErrs) > 0 {
log.Printf("GOAUTH encountered errors for %s:", url)
for _, err := range cmdErrs {
log.Printf(" %v", err)

View File

@ -49,6 +49,8 @@ go get vcs-test.golang.org/auth/or401
go mod tidy
go list all
stdout vcs-test.golang.org/auth/or404
# With cached credentials, re-downloading in debug mode should succeed.
go get -x vcs-test.golang.org/auth/or401
# Clearing GOAUTH credentials should result in failures.
env GOAUTH='off'