2020-10-08 15:06:42 +08:00
|
|
|
package checkpoints
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
2024-07-27 15:42:50 +08:00
|
|
|
"io"
|
|
|
|
|
|
2020-10-08 15:06:42 +08:00
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
2023-10-11 12:21:10 +08:00
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
2020-11-18 19:35:38 +08:00
|
|
|
"github.com/iwind/TeaGo/maps"
|
2020-10-08 15:06:42 +08:00
|
|
|
)
|
|
|
|
|
|
2022-07-16 17:05:37 +08:00
|
|
|
// ResponseBodyCheckpoint ${responseBody}
|
2020-10-08 15:06:42 +08:00
|
|
|
type ResponseBodyCheckpoint struct {
|
|
|
|
|
Checkpoint
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *ResponseBodyCheckpoint) IsRequest() bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 12:21:10 +08:00
|
|
|
func (this *ResponseBodyCheckpoint) RequestValue(req requests.Request, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
2020-10-08 15:06:42 +08:00
|
|
|
value = ""
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-11 12:21:10 +08:00
|
|
|
func (this *ResponseBodyCheckpoint) ResponseValue(req requests.Request, resp *requests.Response, param string, options maps.Map, ruleId int64) (value any, hasRequestBody bool, sysErr error, userErr error) {
|
2022-03-16 17:06:26 +08:00
|
|
|
if resp.ContentLength == 0 {
|
|
|
|
|
value = ""
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 15:06:42 +08:00
|
|
|
value = ""
|
|
|
|
|
if resp != nil && resp.Body != nil {
|
|
|
|
|
if len(resp.BodyData) > 0 {
|
|
|
|
|
value = string(resp.BodyData)
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-08-04 11:34:06 +08:00
|
|
|
body, err := io.ReadAll(resp.Body)
|
2020-10-08 15:06:42 +08:00
|
|
|
if err != nil {
|
|
|
|
|
sysErr = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resp.BodyData = body
|
|
|
|
|
_ = resp.Body.Close()
|
|
|
|
|
value = body
|
2022-08-04 11:34:06 +08:00
|
|
|
resp.Body = io.NopCloser(bytes.NewBuffer(body))
|
2020-10-08 15:06:42 +08:00
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-10-11 12:21:10 +08:00
|
|
|
|
|
|
|
|
func (this *ResponseBodyCheckpoint) CacheLife() utils.CacheLife {
|
|
|
|
|
return utils.CacheMiddleLife
|
|
|
|
|
}
|