@@ -8,40 +8,40 @@ import (
88 "github.com/projectdiscovery/httpx/common/httpx"
99 "github.com/projectdiscovery/nuclei/v3/pkg/input/types"
1010 "github.com/projectdiscovery/useragent"
11+ sliceutil "github.com/projectdiscovery/utils/slice"
1112)
1213
1314var commonHttpPorts = []string {
14- ":80" ,
15- ":8080" ,
15+ "80" ,
16+ "8080" ,
17+ }
18+ var defaultHttpSchemes = []string {
19+ "https" ,
20+ "http" ,
21+ }
22+ var httpFirstSchemes = []string {
23+ "http" ,
24+ "https" ,
1625}
17- var httpSchemesHttpFirst = []string {"http" , "https" }
18- var httpSchemesHttpsFirst = []string {"https" , "http" }
1926
20- // If url contains a port that is commonly used for HTTP,
21- // return http first, otherwise return https first.
27+ // determineSchemeOrder for the input
2228func determineSchemeOrder (input string ) []string {
23- // Full urls (with http(s):// prefix) are not probed
24- _ , port , err := net .SplitHostPort (input )
25- if err == nil {
26- // Check if port is a known HTTP port
27- portWithColon := ":" + port
28- for _ , httpPort := range commonHttpPorts {
29- if portWithColon == httpPort {
30- return httpSchemesHttpFirst
31- }
29+ // if input has port that is commonly used for HTTP, return http then https
30+ if _ , port , err := net .SplitHostPort (input ); err == nil {
31+ if sliceutil .Contains (commonHttpPorts , port ) {
32+ return httpFirstSchemes
3233 }
3334 }
34- return httpSchemesHttpsFirst
35+
36+ return defaultHttpSchemes
3537}
3638
3739// ProbeURL probes the scheme for a URL.
38- // First http scheme tried is selected based on heuristics
40+ // http schemes are selected with heuristics
3941// If none succeeds, probing is abandoned for such URLs.
4042func ProbeURL (input string , httpxclient * httpx.HTTPX ) string {
41-
42- httpSchemesOrdered := determineSchemeOrder (input )
43-
44- for _ , scheme := range httpSchemesOrdered {
43+ schemes := determineSchemeOrder (input )
44+ for _ , scheme := range schemes {
4545 formedURL := fmt .Sprintf ("%s://%s" , scheme , input )
4646 req , err := httpxclient .NewRequest (http .MethodHead , formedURL )
4747 if err != nil {
0 commit comments