NewExternalHTTPClient creates an HTTP client for talking to non-GitHub hosts. It includes debug logging and a User-Agent header but does not attach any authentication tokens or GitHub-specific headers.
(opts ExternalHTTPClientOptions)
| 130 | // It includes debug logging and a User-Agent header but does not attach any |
| 131 | // authentication tokens or GitHub-specific headers. |
| 132 | func NewExternalHTTPClient(opts ExternalHTTPClientOptions) (*http.Client, error) { |
| 133 | clientOpts := ghAPI.ClientOptions{ |
| 134 | Host: "none", |
| 135 | AuthToken: "none", |
| 136 | LogIgnoreEnv: true, |
| 137 | SkipDefaultHeaders: true, |
| 138 | Transport: opts.Transport, |
| 139 | } |
| 140 | |
| 141 | debugEnabled, debugValue := utils.IsDebugEnabled() |
| 142 | logVerboseHTTP := false |
| 143 | if strings.Contains(debugValue, "api") { |
| 144 | logVerboseHTTP = true |
| 145 | } |
| 146 | |
| 147 | if logVerboseHTTP || debugEnabled { |
| 148 | setLog(&clientOpts, opts.Log, opts.LogColorize, logVerboseHTTP) |
| 149 | } |
| 150 | |
| 151 | clientOpts.Headers = map[string]string{ |
| 152 | userAgent: fmt.Sprintf("GitHub CLI %s", opts.AppVersion), |
| 153 | } |
| 154 | |
| 155 | client, err := ghAPI.NewHTTPClient(clientOpts) |
| 156 | if err != nil { |
| 157 | return nil, err |
| 158 | } |
| 159 | |
| 160 | return client, nil |
| 161 | } |
| 162 | |
| 163 | // setLog configures the HTTP logger. A verbose log includes response headers and bodies as the server sent them, so |
| 164 | // its output is sanitized. It isn't colorized, since sanitizing would also neutralize the colors. |