Files
EdgeNode/internal/waf/requests/test_request.go

99 lines
1.8 KiB
Go
Raw Normal View History

2021-07-18 15:51:49 +08:00
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package requests
import (
"bytes"
"io"
"net"
"net/http"
)
type TestRequest struct {
req *http.Request
BodyData []byte
}
func NewTestRequest(raw *http.Request) *TestRequest {
return &TestRequest{
req: raw,
}
}
func (this *TestRequest) WAFSetCacheBody(bodyData []byte) {
this.BodyData = bodyData
}
func (this *TestRequest) WAFGetCacheBody() []byte {
return this.BodyData
}
func (this *TestRequest) WAFRaw() *http.Request {
return this.req
}
func (this *TestRequest) WAFRemoteAddr() string {
return this.req.RemoteAddr
}
func (this *TestRequest) WAFRemoteIP() string {
host, _, err := net.SplitHostPort(this.req.RemoteAddr)
if err != nil {
return this.req.RemoteAddr
} else {
return host
}
}
func (this *TestRequest) WAFReadBody(max int64) (data []byte, err error) {
if this.req.ContentLength > 0 {
2022-08-04 11:34:06 +08:00
data, err = io.ReadAll(io.LimitReader(this.req.Body, max))
2021-07-18 15:51:49 +08:00
}
return
}
func (this *TestRequest) WAFRestoreBody(data []byte) {
if len(data) > 0 {
rawReader := bytes.NewBuffer(data)
buf := make([]byte, 1024)
_, _ = io.CopyBuffer(rawReader, this.req.Body, buf)
2022-08-04 11:34:06 +08:00
this.req.Body = io.NopCloser(rawReader)
2021-07-18 15:51:49 +08:00
}
}
func (this *TestRequest) WAFServerId() int64 {
return 0
}
2021-07-19 10:49:56 +08:00
2021-09-29 11:06:00 +08:00
// WAFClose 关闭当前请求所在的连接
func (this *TestRequest) WAFClose() {
}
2021-07-19 10:49:56 +08:00
func (this *TestRequest) Format(s string) string {
return s
}
2023-10-11 12:21:10 +08:00
func (this *TestRequest) WAFOnAction(action any) bool {
return true
}
func (this *TestRequest) WAFFingerprint() []byte {
return nil
}
func (this *TestRequest) DisableAccessLog() {
}
2023-11-19 09:10:37 +08:00
func (this *TestRequest) DisableStat() {
}
func (this *TestRequest) ProcessResponseHeaders(headers http.Header, status int) {
}
2023-08-08 10:07:24 +08:00
func (this *TestRequest) WAFMaxRequestSize() int64 {
return 1 << 20
}