github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/checkpoints/request_general_header_length.go (about)

     1  package checkpoints
     2  
     3  import (
     4  	"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
     5  	"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
     6  	"github.com/iwind/TeaGo/maps"
     7  	"github.com/iwind/TeaGo/types"
     8  )
     9  
    10  type RequestGeneralHeaderLengthCheckpoint struct {
    11  	Checkpoint
    12  }
    13  
    14  func (this *RequestGeneralHeaderLengthCheckpoint) IsComposed() bool {
    15  	return true
    16  }
    17  
    18  func (this *RequestGeneralHeaderLengthCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
    19  	value = false
    20  
    21  	var headers = options.GetSlice("headers")
    22  	if len(headers) == 0 {
    23  		return
    24  	}
    25  
    26  	var length = options.GetInt("length")
    27  
    28  	for _, header := range headers {
    29  		v := req.WAFRaw().Header.Get(types.String(header))
    30  		if len(v) > length {
    31  			value = true
    32  			break
    33  		}
    34  	}
    35  
    36  	return
    37  }
    38  
    39  func (this *RequestGeneralHeaderLengthCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
    40  	return
    41  }
    42  
    43  func (this *RequestGeneralHeaderLengthCheckpoint) CacheLife() utils.CacheLife {
    44  	return utils.CacheDisabled
    45  }