Files
EdgeNode/internal/waf/checkpoints/request_body.go

47 lines
1.1 KiB
Go
Raw Normal View History

2020-10-08 15:06:42 +08:00
package checkpoints
import (
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
2022-04-08 16:11:05 +08:00
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
"github.com/iwind/TeaGo/maps"
2020-10-08 15:06:42 +08:00
)
2021-07-18 15:51:49 +08:00
// RequestBodyCheckpoint ${requestBody}
2020-10-08 15:06:42 +08:00
type RequestBodyCheckpoint struct {
Checkpoint
}
2022-07-16 17:05:37 +08:00
func (this *RequestBodyCheckpoint) RequestValue(req requests.Request, param string, options maps.Map) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
2022-03-16 17:06:26 +08:00
if this.RequestBodyIsEmpty(req) {
value = ""
return
}
2021-07-18 15:51:49 +08:00
if req.WAFRaw().Body == nil {
2020-10-08 15:06:42 +08:00
value = ""
return
}
2021-07-18 15:51:49 +08:00
var bodyData = req.WAFGetCacheBody()
2022-07-16 17:05:37 +08:00
hasRequestBody = true
2021-07-18 15:51:49 +08:00
if len(bodyData) == 0 {
2022-04-08 16:11:05 +08:00
data, err := req.WAFReadBody(utils.MaxBodySize) // read body
2020-10-08 15:06:42 +08:00
if err != nil {
2022-07-16 17:05:37 +08:00
return "", hasRequestBody, err, nil
2020-10-08 15:06:42 +08:00
}
2021-07-18 15:51:49 +08:00
bodyData = data
req.WAFSetCacheBody(data)
req.WAFRestoreBody(data)
2020-10-08 15:06:42 +08:00
}
2022-07-16 17:05:37 +08:00
return bodyData, hasRequestBody, nil, nil
2020-10-08 15:06:42 +08:00
}
2022-07-16 17:05:37 +08:00
func (this *RequestBodyCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, hasRequestBody bool, sysErr error, userErr error) {
2020-10-08 15:06:42 +08:00
if this.IsRequest() {
return this.RequestValue(req, param, options)
}
return
}