putio: handle rate limit errors

For rate limit errors, "x-ratelimit-reset" header is now respected.
This commit is contained in:
Berkan Teber 2022-03-22 11:40:49 +03:00 committed by Nick Craig-Wood
parent 887cccb2c1
commit 6ea26b508a
5 changed files with 36 additions and 5 deletions

View file

@ -241,7 +241,13 @@ func (o *Object) Open(ctx context.Context, options ...fs.OpenOption) (in io.Read
}
// fs.Debugf(o, "opening file: id=%d", o.file.ID)
resp, err = o.fs.httpClient.Do(req)
return shouldRetry(ctx, err)
if err != nil {
return shouldRetry(ctx, err)
}
if err := checkStatusCode(resp, 200); err != nil {
return shouldRetry(ctx, err)
}
return false, nil
})
if perr, ok := err.(*putio.ErrorResponse); ok && perr.Response.StatusCode >= 400 && perr.Response.StatusCode <= 499 {
_ = resp.Body.Close()