nuclei/pkg/utils/http_probe.go
Tarun Koyalwar dc44105baf
nuclei v3 : misc updates (#4247)
* use parsed options while signing

* update project layout to v3

* fix .gitignore

* remove example template

* misc updates

* bump tlsx version

* hide template sig warning with env

* js: retain value while using log

* fix nil pointer derefernce

* misc doc update

---------

Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com>
2023-10-17 17:44:13 +05:30

34 lines
763 B
Go

package utils
import (
"fmt"
"net/http"
"github.com/corpix/uarand"
"github.com/projectdiscovery/httpx/common/httpx"
)
var (
HttpSchemes = []string{"https", "http"}
)
// probeURL probes the scheme for a URL. first HTTPS is tried
// and if any errors occur http is tried. If none succeeds, probing
// is abandoned for such URLs.
func ProbeURL(input string, httpxclient *httpx.HTTPX) string {
for _, scheme := range HttpSchemes {
formedURL := fmt.Sprintf("%s://%s", scheme, input)
req, err := httpxclient.NewRequest(http.MethodHead, formedURL)
if err != nil {
continue
}
req.Header.Set("User-Agent", uarand.GetRandom())
if _, err = httpxclient.Do(req, httpx.UnsafeOptions{}); err != nil {
continue
}
return formedURL
}
return ""
}