github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/checkpoints/request_cookies.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  	"net/url"
     8  	"strings"
     9  )
    10  
    11  type RequestCookiesCheckpoint struct {
    12  	Checkpoint
    13  }
    14  
    15  func (this *RequestCookiesCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
    16  	var cookies = []string{}
    17  	for _, cookie := range req.WAFRaw().Cookies() {
    18  		cookies = append(cookies, url.QueryEscape(cookie.Name)+"="+url.QueryEscape(cookie.Value))
    19  	}
    20  	value = strings.Join(cookies, "&")
    21  	return
    22  }
    23  
    24  func (this *RequestCookiesCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
    25  	if this.IsRequest() {
    26  		return this.RequestValue(req, param, options, ruleId)
    27  	}
    28  	return
    29  }
    30  
    31  func (this *RequestCookiesCheckpoint) CacheLife() utils.CacheLife {
    32  	return utils.CacheShortLife
    33  }