mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-27 02:37:38 +00:00
net/tshttpproxy: log when we're using a proxy
Updates #11196 Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: Id6334c10f52f4cfbda9f03dc8096ab7a6c54a088
This commit is contained in:
parent
713d2928b1
commit
e8d2fc7f7f
@ -19,6 +19,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/net/http/httpproxy"
|
"golang.org/x/net/http/httpproxy"
|
||||||
|
"tailscale.com/util/mak"
|
||||||
)
|
)
|
||||||
|
|
||||||
// InvalidateCache invalidates the package-level cache for ProxyFromEnvironment.
|
// InvalidateCache invalidates the package-level cache for ProxyFromEnvironment.
|
||||||
@ -117,10 +118,33 @@ func SetSelfProxy(addrs ...string) {
|
|||||||
// For example, WPAD PAC files on Windows.
|
// For example, WPAD PAC files on Windows.
|
||||||
var sysProxyFromEnv func(*http.Request) (*url.URL, error)
|
var sysProxyFromEnv func(*http.Request) (*url.URL, error)
|
||||||
|
|
||||||
|
// These variables track whether we've printed a log message for a given proxy
|
||||||
|
// URL; we only print them once to avoid log spam.
|
||||||
|
var (
|
||||||
|
logMessageMu sync.Mutex
|
||||||
|
logMessagePrinted map[string]bool
|
||||||
|
)
|
||||||
|
|
||||||
// ProxyFromEnvironment is like the standard library's http.ProxyFromEnvironment
|
// ProxyFromEnvironment is like the standard library's http.ProxyFromEnvironment
|
||||||
// but additionally does OS-specific proxy lookups if the environment variables
|
// but additionally does OS-specific proxy lookups if the environment variables
|
||||||
// alone don't specify a proxy.
|
// alone don't specify a proxy.
|
||||||
func ProxyFromEnvironment(req *http.Request) (*url.URL, error) {
|
func ProxyFromEnvironment(req *http.Request) (ret *url.URL, _ error) {
|
||||||
|
defer func() {
|
||||||
|
if ret == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ss := ret.String()
|
||||||
|
|
||||||
|
logMessageMu.Lock()
|
||||||
|
defer logMessageMu.Unlock()
|
||||||
|
if logMessagePrinted[ss] {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Printf("tshttpproxy: using proxy %q for URL: %q", ss, req.URL.String())
|
||||||
|
mak.Set(&logMessagePrinted, ss, true)
|
||||||
|
}()
|
||||||
|
|
||||||
localProxyFunc := getProxyFunc()
|
localProxyFunc := getProxyFunc()
|
||||||
u, err := localProxyFunc(req.URL)
|
u, err := localProxyFunc(req.URL)
|
||||||
if u != nil && err == nil {
|
if u != nil && err == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user