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 | clientOpts.Log = opts.Log |
| 149 | clientOpts.LogColorize = opts.LogColorize |
| 150 | clientOpts.LogVerboseHTTP = logVerboseHTTP |
| 151 | } |
| 152 | |
| 153 | clientOpts.Headers = map[string]string{ |
| 154 | userAgent: fmt.Sprintf("GitHub CLI %s", opts.AppVersion), |
| 155 | } |
| 156 | |
| 157 | client, err := ghAPI.NewHTTPClient(clientOpts) |
| 158 | if err != nil { |
| 159 | return nil, err |
| 160 | } |
| 161 | |
| 162 | return client, nil |
| 163 | } |
| 164 | |
| 165 | func NewCachedHTTPClient(httpClient *http.Client, ttl time.Duration) *http.Client { |
| 166 | newClient := *httpClient |