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

Function NewExternalHTTPClient

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

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

Calls 3

IsDebugEnabledFunction · 0.92
setLogFunction · 0.85
ContainsMethod · 0.80