Skip to content

Commit 2c7e88f

Browse files
feat(client): send X-Stainless-Timeout header
1 parent 95e28e4 commit 2c7e88f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

internal/requestconfig/requestconfig.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ func NewRequestConfig(ctx context.Context, method string, u string, body interfa
138138

139139
req.Header.Set("Accept", "application/json")
140140
req.Header.Set("X-Stainless-Retry-Count", "0")
141+
req.Header.Set("X-Stainless-Timeout", "0")
141142
for k, v := range getDefaultHeaders() {
142143
req.Header.Add(k, v)
143144
}
@@ -157,6 +158,18 @@ func NewRequestConfig(ctx context.Context, method string, u string, body interfa
157158
if err != nil {
158159
return nil, err
159160
}
161+
162+
// This must run after `cfg.Apply(...)` above in case the request timeout gets modified. We also only
163+
// apply our own logic for it if it's still "0" from above. If it's not, then it was deleted or modified
164+
// by the user and we should respect that.
165+
if req.Header.Get("X-Stainless-Timeout") == "0" {
166+
if cfg.RequestTimeout == time.Duration(0) {
167+
req.Header.Del("X-Stainless-Timeout")
168+
} else {
169+
req.Header.Set("X-Stainless-Timeout", strconv.Itoa(int(cfg.RequestTimeout.Seconds())))
170+
}
171+
}
172+
160173
return &cfg, nil
161174
}
162175

0 commit comments

Comments
 (0)