github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/checkpoints/request_headers.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  	"sort"
     8  	"strings"
     9  )
    10  
    11  type RequestHeadersCheckpoint struct {
    12  	Checkpoint
    13  }
    14  
    15  func (this *RequestHeadersCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
    16  	var headers = []string{}
    17  	for k, v := range req.WAFRaw().Header {
    18  		for _, subV := range v {
    19  			headers = append(headers, k+": "+subV)
    20  		}
    21  	}
    22  	sort.Strings(headers)
    23  	value = strings.Join(headers, "\n")
    24  	return
    25  }
    26  
    27  func (this *RequestHeadersCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
    28  	if this.IsRequest() {
    29  		return this.RequestValue(req, param, options, ruleId)
    30  	}
    31  	return
    32  }
    33  
    34  func (this *RequestHeadersCheckpoint) CacheLife() utils.CacheLife {
    35  	return utils.CacheShortLife
    36  }