Source file src/cmd/go/internal/auth/auth.go

     1  // Copyright 2019 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // Package auth provides access to user-provided authentication credentials.
     6  package auth
     7  
     8  import "net/http"
     9  
    10  // AddCredentials fills in the user's credentials for req, if any.
    11  // The return value reports whether any matching credentials were found.
    12  func AddCredentials(req *http.Request) (added bool) {
    13  	host := req.URL.Hostname()
    14  
    15  	// TODO(golang.org/issue/26232): Support arbitrary user-provided credentials.
    16  	netrcOnce.Do(readNetrc)
    17  	for _, l := range netrc {
    18  		if l.machine == host {
    19  			req.SetBasicAuth(l.login, l.password)
    20  			return true
    21  		}
    22  	}
    23  
    24  	return false
    25  }
    26  

View as plain text