github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/checkpoints/request_raw_remote_addr.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"
     8  )
     9  
    10  type RequestRawRemoteAddrCheckpoint struct {
    11  	Checkpoint
    12  }
    13  
    14  func (this *RequestRawRemoteAddrCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
    15  	host, _, err := net.SplitHostPort(req.WAFRaw().RemoteAddr)
    16  	if err == nil {
    17  		value = host
    18  	} else {
    19  		value = req.WAFRaw().RemoteAddr
    20  	}
    21  	return
    22  }
    23  
    24  func (this *RequestRawRemoteAddrCheckpoint) 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 *RequestRawRemoteAddrCheckpoint) CacheLife() utils.CacheLife {
    32  	return utils.CacheShortLife
    33  }