mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-31 18:46:36 +08:00
优化WAF性能
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
package checkpoints
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Checkpoint struct {
|
||||
}
|
||||
|
||||
@@ -30,3 +35,16 @@ func (this *Checkpoint) Start() {
|
||||
func (this *Checkpoint) Stop() {
|
||||
|
||||
}
|
||||
|
||||
func (this *Checkpoint) RequestBodyIsEmpty(req requests.Request) bool {
|
||||
if req.WAFRaw().ContentLength == 0 {
|
||||
return true
|
||||
}
|
||||
|
||||
var method = req.WAFRaw().Method
|
||||
if method == http.MethodHead || method == http.MethodGet {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -18,6 +18,11 @@ func (this *RequestAllCheckpoint) RequestValue(req requests.Request, param strin
|
||||
valueBytes = append(valueBytes, req.WAFRaw().URL.RequestURI()...)
|
||||
}
|
||||
|
||||
if this.RequestBodyIsEmpty(req) {
|
||||
value = valueBytes
|
||||
return
|
||||
}
|
||||
|
||||
if req.WAFRaw().Body != nil {
|
||||
valueBytes = append(valueBytes, ' ')
|
||||
|
||||
|
||||
@@ -11,6 +11,11 @@ type RequestBodyCheckpoint struct {
|
||||
}
|
||||
|
||||
func (this *RequestBodyCheckpoint) RequestValue(req requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||
if this.RequestBodyIsEmpty(req) {
|
||||
value = ""
|
||||
return
|
||||
}
|
||||
|
||||
if req.WAFRaw().Body == nil {
|
||||
value = ""
|
||||
return
|
||||
|
||||
@@ -12,6 +12,11 @@ type RequestFormArgCheckpoint struct {
|
||||
}
|
||||
|
||||
func (this *RequestFormArgCheckpoint) RequestValue(req requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||
if this.RequestBodyIsEmpty(req) {
|
||||
value = ""
|
||||
return
|
||||
}
|
||||
|
||||
if req.WAFRaw().Body == nil {
|
||||
value = ""
|
||||
return
|
||||
|
||||
@@ -17,6 +17,11 @@ type RequestUploadCheckpoint struct {
|
||||
}
|
||||
|
||||
func (this *RequestUploadCheckpoint) RequestValue(req requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||
if this.RequestBodyIsEmpty(req) {
|
||||
value = ""
|
||||
return
|
||||
}
|
||||
|
||||
value = ""
|
||||
if param == "minSize" || param == "maxSize" {
|
||||
value = 0
|
||||
|
||||
@@ -22,6 +22,11 @@ func (this *ResponseBodyCheckpoint) RequestValue(req requests.Request, param str
|
||||
}
|
||||
|
||||
func (this *ResponseBodyCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
||||
if resp.ContentLength == 0 {
|
||||
value = ""
|
||||
return
|
||||
}
|
||||
|
||||
value = ""
|
||||
if resp != nil && resp.Body != nil {
|
||||
if len(resp.BodyData) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user