mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-22 20:05:27 +00:00
retry with 504 status code (timeouts) (#2852)
* Incase of 504/timeouts, do retry * Update the version and pass the custom policy from outside
This commit is contained in:
parent
8a75cb2574
commit
19b56570b5
@ -2,6 +2,7 @@ package nucleicloud
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -27,10 +28,21 @@ const (
|
|||||||
resultSize = 100
|
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
|
// New returns a nuclei-cloud API client
|
||||||
func New(baseURL, apiKey string) *Client {
|
func New(baseURL, apiKey string) *Client {
|
||||||
options := retryablehttp.DefaultOptionsSingle
|
options := retryablehttp.DefaultOptionsSingle
|
||||||
options.Timeout = 15 * time.Second
|
options.Timeout = 15 * time.Second
|
||||||
|
options.CheckRetry = HTTPErrorRetryPolicy()
|
||||||
client := retryablehttp.NewClient(options)
|
client := retryablehttp.NewClient(options)
|
||||||
|
|
||||||
baseAppURL := baseURL
|
baseAppURL := baseURL
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user