diff --git a/api/http_client.go b/api/http_client.go index 53225b139..9f2d59ce3 100644 --- a/api/http_client.go +++ b/api/http_client.go @@ -23,6 +23,7 @@ type HTTPClientOptions struct { EnableCache bool Log io.Writer LogColorize bool + LogVerboseHTTP bool SkipAcceptHeaders bool } @@ -35,10 +36,15 @@ func NewHTTPClient(opts HTTPClientOptions) (*http.Client, error) { LogIgnoreEnv: true, } - if debugEnabled, debugValue := utils.IsDebugEnabled(); debugEnabled { + debugEnabled, debugValue := utils.IsDebugEnabled() + if strings.Contains(debugValue, "api") { + opts.LogVerboseHTTP = true + } + + if opts.LogVerboseHTTP || debugEnabled { clientOpts.Log = opts.Log clientOpts.LogColorize = opts.LogColorize - clientOpts.LogVerboseHTTP = strings.Contains(debugValue, "api") + clientOpts.LogVerboseHTTP = opts.LogVerboseHTTP } headers := map[string]string{ diff --git a/api/http_client_test.go b/api/http_client_test.go index 5bfe0aa05..b1e84e582 100644 --- a/api/http_client_test.go +++ b/api/http_client_test.go @@ -6,7 +6,6 @@ import ( "io" "net/http" "net/http/httptest" - "os" "regexp" "strings" "testing" @@ -19,16 +18,14 @@ import ( func TestNewHTTPClient(t *testing.T) { type args struct { - config tokenGetter - appVersion string - setAccept bool + config tokenGetter + appVersion string + setAccept bool + logVerboseHTTP bool } tests := []struct { name string args args - envDebug string - setGhDebug bool - envGhDebug string host string wantHeader map[string]string wantStderr string @@ -36,9 +33,10 @@ func TestNewHTTPClient(t *testing.T) { { name: "github.com with Accept header", args: args{ - config: tinyConfig{"github.com:oauth_token": "MYTOKEN"}, - appVersion: "v1.2.3", - setAccept: true, + config: tinyConfig{"github.com:oauth_token": "MYTOKEN"}, + appVersion: "v1.2.3", + setAccept: true, + logVerboseHTTP: false, }, host: "github.com", wantHeader: map[string]string{ @@ -51,9 +49,10 @@ func TestNewHTTPClient(t *testing.T) { { name: "github.com no Accept header", args: args{ - config: tinyConfig{"github.com:oauth_token": "MYTOKEN"}, - appVersion: "v1.2.3", - setAccept: false, + config: tinyConfig{"github.com:oauth_token": "MYTOKEN"}, + appVersion: "v1.2.3", + setAccept: false, + logVerboseHTTP: false, }, host: "github.com", wantHeader: map[string]string{ @@ -66,9 +65,10 @@ func TestNewHTTPClient(t *testing.T) { { name: "github.com no authentication token", args: args{ - config: tinyConfig{"example.com:oauth_token": "MYTOKEN"}, - appVersion: "v1.2.3", - setAccept: true, + config: tinyConfig{"example.com:oauth_token": "MYTOKEN"}, + appVersion: "v1.2.3", + setAccept: true, + logVerboseHTTP: false, }, host: "github.com", wantHeader: map[string]string{ @@ -81,45 +81,12 @@ func TestNewHTTPClient(t *testing.T) { { name: "github.com in verbose mode", args: args{ - config: tinyConfig{"github.com:oauth_token": "MYTOKEN"}, - appVersion: "v1.2.3", - setAccept: true, + config: tinyConfig{"github.com:oauth_token": "MYTOKEN"}, + appVersion: "v1.2.3", + setAccept: true, + logVerboseHTTP: true, }, - host: "github.com", - envDebug: "api", - setGhDebug: false, - wantHeader: map[string]string{ - "authorization": "token MYTOKEN", - "user-agent": "GitHub CLI v1.2.3", - "accept": "application/vnd.github.merge-info-preview+json, application/vnd.github.nebula-preview", - }, - wantStderr: heredoc.Doc(` - * Request at