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