mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-08 03:00:27 +08:00
WAF增加多个动作
This commit is contained in:
67
internal/waf/requests/test_request.go
Normal file
67
internal/waf/requests/test_request.go
Normal file
@@ -0,0 +1,67 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package requests
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"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 {
|
||||
data, err = ioutil.ReadAll(io.LimitReader(this.req.Body, max))
|
||||
}
|
||||
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)
|
||||
this.req.Body = ioutil.NopCloser(rawReader)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *TestRequest) WAFServerId() int64 {
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user