github.com/projectdiscovery/nuclei/v2@v2.9.15/pkg/protocols/http/cluster.go (about)

     1  package http
     2  
     3  import (
     4  	sliceutil "github.com/projectdiscovery/utils/slice"
     5  	"golang.org/x/exp/maps"
     6  )
     7  
     8  // CanCluster returns true if the request can be clustered.
     9  //
    10  // This used by the clustering engine to decide whether two requests
    11  // are similar enough to be considered one and can be checked by
    12  // just adding the matcher/extractors for the request and the correct IDs.
    13  func (request *Request) CanCluster(other *Request) bool {
    14  	if len(request.Payloads) > 0 || len(request.Fuzzing) > 0 || len(request.Raw) > 0 || len(request.Body) > 0 || request.Unsafe || request.NeedsRequestCondition() || request.Name != "" {
    15  		return false
    16  	}
    17  	if request.Method != other.Method ||
    18  		request.MaxRedirects != other.MaxRedirects ||
    19  		request.CookieReuse != other.CookieReuse ||
    20  		request.Redirects != other.Redirects {
    21  		return false
    22  	}
    23  	if !sliceutil.Equal(request.Path, other.Path) {
    24  		return false
    25  	}
    26  	if !maps.Equal(request.Headers, other.Headers) {
    27  		return false
    28  	}
    29  	return true
    30  }