mirror of https://github.com/daffainfo/nuclei.git
retry with 504 status code (timeouts) (#2852)
* Incase of 504/timeouts, do retry * Update the version and pass the custom policy from outsidedev
parent
8a75cb2574
commit
19b56570b5
|
@ -2,6 +2,7 @@ package nucleicloud
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
@ -27,10 +28,21 @@ const (
|
|||
resultSize = 100
|
||||
)
|
||||
|
||||
// HTTPErrorRetryPolicy is to retry for HTTPCodes >= 500.
|
||||
func HTTPErrorRetryPolicy() func(ctx context.Context, resp *http.Response, err error) (bool, error) {
|
||||
return func(ctx context.Context, resp *http.Response, err error) (bool, error) {
|
||||
if resp.StatusCode >= http.StatusInternalServerError {
|
||||
return true, errors.New(resp.Status)
|
||||
}
|
||||
return retryablehttp.CheckRecoverableErrors(ctx, resp, err)
|
||||
}
|
||||
}
|
||||
|
||||
// New returns a nuclei-cloud API client
|
||||
func New(baseURL, apiKey string) *Client {
|
||||
options := retryablehttp.DefaultOptionsSingle
|
||||
options.Timeout = 15 * time.Second
|
||||
options.CheckRetry = HTTPErrorRetryPolicy()
|
||||
client := retryablehttp.NewClient(options)
|
||||
|
||||
baseAppURL := baseURL
|
||||
|
|
Loading…
Reference in New Issue