github.com/TeaOSLab/EdgeNode@v1.3.8/internal/waf/checkpoints/request_remote_port.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  	"github.com/iwind/TeaGo/types"
     8  	"net"
     9  )
    10  
    11  type RequestRemotePortCheckpoint struct {
    12  	Checkpoint
    13  }
    14  
    15  func (this *RequestRemotePortCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
    16  	_, port, err := net.SplitHostPort(req.WAFRaw().RemoteAddr)
    17  	if err == nil {
    18  		value = types.Int(port)
    19  	} else {
    20  		value = 0
    21  	}
    22  	return
    23  }
    24  
    25  func (this *RequestRemotePortCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
    26  	if this.IsRequest() {
    27  		return this.RequestValue(req, param, options, ruleId)
    28  	}
    29  	return
    30  }
    31  
    32  func (this *RequestRemotePortCheckpoint) CacheLife() utils.CacheLife {
    33  	return utils.CacheMiddleLife
    34  }