77 "strings"
88 "time"
99
10+ "github.com/cli/cli/v2/internal/gh/ghtelemetry"
1011 "github.com/cli/cli/v2/utils"
1112 ghAPI "github.com/cli/go-gh/v2/pkg/api"
1213 ghauth "github.com/cli/go-gh/v2/pkg/auth"
@@ -26,6 +27,7 @@ type HTTPClientOptions struct {
2627 LogColorize bool
2728 LogVerboseHTTP bool
2829 SkipDefaultHeaders bool
30+ TelemetryDisabler ghtelemetry.Disabler
2931}
3032
3133func NewHTTPClient (opts HTTPClientOptions ) (* http.Client , error ) {
@@ -74,6 +76,13 @@ func NewHTTPClient(opts HTTPClientOptions) (*http.Client, error) {
7476 client .Transport = AddAuthTokenHeader (client .Transport , opts .Config )
7577 }
7678
79+ if opts .TelemetryDisabler != nil {
80+ client .Transport = telemetryDisablerTransport {
81+ wrappedTransport : client .Transport ,
82+ telemetryDisabler : opts .TelemetryDisabler ,
83+ }
84+ }
85+
7786 return client , nil
7887}
7988
@@ -147,3 +156,15 @@ func getHost(r *http.Request) string {
147156 }
148157 return r .URL .Host
149158}
159+
160+ type telemetryDisablerTransport struct {
161+ wrappedTransport http.RoundTripper
162+ telemetryDisabler ghtelemetry.Disabler
163+ }
164+
165+ func (t telemetryDisablerTransport ) RoundTrip (req * http.Request ) (* http.Response , error ) {
166+ if ghauth .IsEnterprise (getHost (req )) {
167+ t .telemetryDisabler .Disable ()
168+ }
169+ return t .wrappedTransport .RoundTrip (req )
170+ }
0 commit comments