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

Function NewExternalHTTPClient

api/http_client.go:102–133  ·  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

100// It includes debug logging and a User-Agent header but does not attach any
101// authentication tokens or GitHub-specific headers.
102func NewExternalHTTPClient(opts ExternalHTTPClientOptions) (*http.Client, error) {
103 clientOpts := ghAPI.ClientOptions{
104 Host: "none",
105 AuthToken: "none",
106 LogIgnoreEnv: true,
107 SkipDefaultHeaders: true,
108 Transport: opts.Transport,
109 }
110
111 debugEnabled, debugValue := utils.IsDebugEnabled()
112 logVerboseHTTP := false
113 if strings.Contains(debugValue, "api") {
114 logVerboseHTTP = true
115 }
116
117 if logVerboseHTTP || debugEnabled {
118 clientOpts.Log = opts.Log
119 clientOpts.LogColorize = opts.LogColorize
120 clientOpts.LogVerboseHTTP = logVerboseHTTP
121 }
122
123 clientOpts.Headers = map[string]string{
124 userAgent: fmt.Sprintf("GitHub CLI %s", opts.AppVersion),
125 }
126
127 client, err := ghAPI.NewHTTPClient(clientOpts)
128 if err != nil {
129 return nil, err
130 }
131
132 return client, nil
133}
134
135func NewCachedHTTPClient(httpClient *http.Client, ttl time.Duration) *http.Client {
136 newClient := *httpClient

Callers 2

externalHttpClientFuncFunction · 0.92

Calls 2

IsDebugEnabledFunction · 0.92
ContainsMethod · 0.80

Tested by 1