2020-10-08 15:06:42 +08:00
|
|
|
package checkpoints
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"bytes"
|
|
|
|
|
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
2020-11-18 19:35:38 +08:00
|
|
|
"github.com/iwind/TeaGo/maps"
|
2020-10-08 15:06:42 +08:00
|
|
|
"io/ioutil"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// ${responseBody}
|
|
|
|
|
type ResponseBodyCheckpoint struct {
|
|
|
|
|
Checkpoint
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (this *ResponseBodyCheckpoint) IsRequest() bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-18 19:35:38 +08:00
|
|
|
func (this *ResponseBodyCheckpoint) RequestValue(req *requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
2020-10-08 15:06:42 +08:00
|
|
|
value = ""
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-18 19:35:38 +08:00
|
|
|
func (this *ResponseBodyCheckpoint) ResponseValue(req *requests.Request, resp *requests.Response, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
|
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
|
|
|
|
|
}
|
|
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
sysErr = err
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
resp.BodyData = body
|
|
|
|
|
_ = resp.Body.Close()
|
|
|
|
|
value = body
|
|
|
|
|
resp.Body = ioutil.NopCloser(bytes.NewBuffer(body))
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|