net/tshttpproxy: support basic auth when available (#1354)

This allows proxy URLs such as:

    http://azurediamond:hunter2@192.168.122.154:38274

to be used in order to dial out to control, logs or derp servers.

Signed-off-by: Christine Dodrill <xe@tailscale.com>
This commit is contained in:
Christine Dodrill
2021-02-17 16:01:47 -05:00
committed by GitHub
parent d98ef5699d
commit 3e5c3e932c
2 changed files with 61 additions and 0 deletions

View File

@@ -74,6 +74,18 @@ func GetAuthHeader(u *url.URL) (string, error) {
if sysAuthHeader != nil {
return sysAuthHeader(u)
}
if user := u.User.Username(); user != "" {
pass, ok := u.User.Password()
if !ok {
return "", nil
}
req := &http.Request{Header: make(http.Header)}
req.SetBasicAuth(user, pass)
return req.Header.Get("Authorization"), nil
}
return "", nil
}