Skip to content

Commit

Permalink
feat(client): send X-Stainless-Timeout header (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] committed Feb 4, 2025
1 parent f873275 commit deb01b6
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions internal/requestconfig/requestconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func NewRequestConfig(ctx context.Context, method string, u string, body interfa

req.Header.Set("Accept", "application/json")
req.Header.Set("X-Stainless-Retry-Count", "0")
req.Header.Set("X-Stainless-Timeout", "0")
for k, v := range getDefaultHeaders() {
req.Header.Add(k, v)
}
Expand All @@ -157,6 +158,18 @@ func NewRequestConfig(ctx context.Context, method string, u string, body interfa
if err != nil {
return nil, err
}

// This must run after `cfg.Apply(...)` above in case the request timeout gets modified. We also only
// apply our own logic for it if it's still "0" from above. If it's not, then it was deleted or modified
// by the user and we should respect that.
if req.Header.Get("X-Stainless-Timeout") == "0" {
if cfg.RequestTimeout == time.Duration(0) {
req.Header.Del("X-Stainless-Timeout")
} else {
req.Header.Set("X-Stainless-Timeout", strconv.Itoa(int(cfg.RequestTimeout.Seconds())))
}
}

return &cfg, nil
}

Expand Down

0 comments on commit deb01b6

Please sign in to comment.