MCPcopy Index your code
hub / github.com/cli/cli / NewExternalHTTPClient

Function NewExternalHTTPClient

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

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

Callers 2

externalHttpClientFuncFunction · 0.92

Calls 2

IsDebugEnabledFunction · 0.92
ContainsMethod · 0.80

Tested by 1