MCPcopy Create free account
hub / github.com/cli/cli / NewExternalHTTPClient

Function NewExternalHTTPClient

api/http_client.go:132–163  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

130// It includes debug logging and a User-Agent header but does not attach any
131// authentication tokens or GitHub-specific headers.
132func 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
165func NewCachedHTTPClient(httpClient *http.Client, ttl time.Duration) *http.Client {
166 newClient := *httpClient

Callers 2

externalHttpClientFuncFunction · 0.92

Calls 2

IsDebugEnabledFunction · 0.92
ContainsMethod · 0.80

Tested by 1