Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(client): expose DebugMode field #477

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions fastly/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ var UserAgent = fmt.Sprintf("FastlyGo/%s (+%s; %s)",
type Client struct {
// Address is the address of Fastly's API endpoint.
Address string
// DebugMode enables HTTP request/response dumps.
DebugMode bool
// HTTPClient is the HTTP client to use. If one is not provided, a default
// client will be used.
HTTPClient *http.Client

// apiKey is the Fastly API key to authenticate requests.
apiKey string
// debugMode enables HTTP request/response dumps.
debugMode bool
// remaining is last observed value of http header Fastly-RateLimit-Remaining
remaining int
// reset is last observed value of http header Fastly-RateLimit-Reset
Expand Down Expand Up @@ -121,7 +121,7 @@ func NewClientForEndpoint(key string, endpoint string) (*Client, error) {
client := &Client{apiKey: key, Address: endpoint}

if endpoint, ok := os.LookupEnv(DebugEnvVar); ok && endpoint == "true" {
client.debugMode = true
client.DebugMode = true
}

return client.init()
Expand Down Expand Up @@ -307,7 +307,7 @@ func (c *Client) Request(verb, p string, ro *RequestOptions) (*http.Response, er
defer c.updateLock.Unlock()
}

if c.debugMode {
if c.DebugMode {
r := req.Clone(context.Background())
r.Header.Del("Fastly-Key")
dump, _ := httputil.DumpRequest(r, true)
Expand All @@ -317,7 +317,7 @@ func (c *Client) Request(verb, p string, ro *RequestOptions) (*http.Response, er
// nosemgrep: trailofbits.go.invalid-usage-of-modified-variable.invalid-usage-of-modified-variable
resp, err := checkResp(c.HTTPClient.Do(req))

if c.debugMode && resp != nil {
if c.DebugMode && resp != nil {
dump, _ := httputil.DumpResponse(resp, true)
fmt.Printf("http.Response (dump): %q\n", dump)
}
Expand Down