Using retryablehttp for templates loading (#3291)

* Using retryablehttp for templates loading

* Update compile_test.go
dev
Mzack9999 2023-02-09 14:45:44 +01:00 committed by GitHub
parent a62e57f6c0
commit 454a883241
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -3,7 +3,6 @@ package templates
import (
"fmt"
"io"
"net/http"
"reflect"
"github.com/pkg/errors"
@ -15,6 +14,7 @@ import (
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/offlinehttp"
"github.com/projectdiscovery/nuclei/v2/pkg/templates/cache"
"github.com/projectdiscovery/nuclei/v2/pkg/utils"
"github.com/projectdiscovery/retryablehttp-go"
stringsutil "github.com/projectdiscovery/utils/strings"
)
@ -40,7 +40,9 @@ func Parse(filePath string, preprocessor Preprocessor, options protocols.Execute
var reader io.ReadCloser
if utils.IsURL(filePath) {
resp, err := http.Get(filePath)
//todo:instead of creating a new client each time, a default one should be reused (same as the standard library)
// use retryablehttp (tls verification is enabled by default in the standard library)
resp, err := retryablehttp.DefaultClient().Get(filePath)
if err != nil {
return nil, err
}

View File

@ -2,6 +2,7 @@ package templates_test
import (
"context"
"fmt"
"log"
"testing"
"time"
@ -80,7 +81,7 @@ func Test_ParseFromURL(t *testing.T) {
}
setup()
got, err := templates.Parse(filePath, nil, executerOpts)
require.Nil(t, err, "could not parse template")
require.Nilf(t, err, "could not parse template (%s)", fmt.Sprint(err))
require.Equal(t, expectedTemplate.ID, got.ID)
require.Equal(t, expectedTemplate.Info, got.Info)
require.Equal(t, expectedTemplate.TotalRequests, got.TotalRequests)