github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/checkpoints/request_all.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  )
     8  
     9  // RequestAllCheckpoint ${requestAll}
    10  type RequestAllCheckpoint struct {
    11  	Checkpoint
    12  }
    13  
    14  func (this *RequestAllCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
    15  	var valueBytes = [][]byte{}
    16  	if len(req.WAFRaw().RequestURI) > 0 {
    17  		valueBytes = append(valueBytes, []byte(req.WAFRaw().RequestURI))
    18  	} else if req.WAFRaw().URL != nil {
    19  		valueBytes = append(valueBytes, []byte(req.WAFRaw().URL.RequestURI()))
    20  	}
    21  
    22  	if this.RequestBodyIsEmpty(req) {
    23  		value = valueBytes
    24  		return
    25  	}
    26  
    27  	if req.WAFRaw().Body != nil {
    28  		var bodyData = req.WAFGetCacheBody()
    29  		hasRequestBody = true
    30  		if len(bodyData) == 0 {
    31  			data, err := req.WAFReadBody(req.WAFMaxRequestSize()) // read body
    32  			if err != nil {
    33  				return "", hasRequestBody, err, nil
    34  			}
    35  
    36  			bodyData = data
    37  			req.WAFSetCacheBody(data)
    38  			req.WAFRestoreBody(data)
    39  		}
    40  		if len(bodyData) > 0 {
    41  			valueBytes = append(valueBytes, bodyData)
    42  		}
    43  	}
    44  
    45  	value = valueBytes
    46  
    47  	return
    48  }
    49  
    50  func (this *RequestAllCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
    51  	value = ""
    52  	if this.IsRequest() {
    53  		return this.RequestValue(req, param, options, ruleId)
    54  	}
    55  	return
    56  }
    57  
    58  func (this *RequestAllCheckpoint) CacheLife() utils.CacheLife {
    59  	return utils.CacheShortLife
    60  }