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

fix: make retry after header value case insensitive #61

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 7 additions & 2 deletions zcon/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,16 @@ func (c *Client) GetContentType() string {
}

func getRetryAfter(resp *http.Response, l logger.Logger) time.Duration {
if s, ok := resp.Header["Retry-After"]; ok {
if sleep, err := strconv.ParseInt(s[0], 10, 64); err == nil {

if s := resp.Header.Get("Retry-After"); s != "" {
if sleep, err := strconv.ParseInt(s, 10, 64); err == nil {
l.Printf("[INFO] got Retry-After from header:%s\n", s)
return time.Second * time.Duration(sleep)
} else {
dur, err := time.ParseDuration(s)
if err == nil {
return dur
}
l.Printf("[INFO] error getting Retry-After from header:%s\n", err)
}
}
Expand Down
8 changes: 6 additions & 2 deletions zia/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,15 @@ func (c *Client) GetContentType() string {
}

func getRetryAfter(resp *http.Response, l logger.Logger) time.Duration {
if s, ok := resp.Header["Retry-After"]; ok {
if sleep, err := strconv.ParseInt(s[0], 10, 64); err == nil {
if s := resp.Header.Get("Retry-After"); s != "" {
if sleep, err := strconv.ParseInt(s, 10, 64); err == nil {
l.Printf("[INFO] got Retry-After from header:%s\n", s)
return time.Second * time.Duration(sleep)
} else {
dur, err := time.ParseDuration(s)
if err == nil {
return dur
}
l.Printf("[INFO] error getting Retry-After from header:%s\n", err)
}
}
Expand Down
14 changes: 9 additions & 5 deletions zpa/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
"sync"
"time"

"github.com/hashicorp/go-retryablehttp"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
logger "github.com/SecurityGeekIO/zscaler-sdk-go/v2/logger"
rl "github.com/SecurityGeekIO/zscaler-sdk-go/v2/ratelimiter"
"github.com/hashicorp/go-retryablehttp"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
)

const (
Expand Down Expand Up @@ -215,10 +215,14 @@ func (c *Config) GetHTTPClient() *http.Client {
retryableClient.Backoff = func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration {
if resp != nil {
if resp.StatusCode == http.StatusTooManyRequests || resp.StatusCode == http.StatusServiceUnavailable {
// TODO: ask backend to implement such header, instead of using the logic below
if s, ok := resp.Header["Retry-After"]; ok {
if sleep, err := strconv.ParseInt(s[0], 10, 64); err == nil {
if s := resp.Header.Get("Retry-After"); s != "" {
if sleep, err := strconv.ParseInt(s, 10, 64); err == nil {
return time.Second * time.Duration(sleep)
} else {
dur, err := time.ParseDuration(s)
if err == nil {
return dur
}
}
}
}
Expand Down