Initial commit (code only without large binaries)
This commit is contained in:
52
EdgeNode/internal/waf/requests/request.go
Normal file
52
EdgeNode/internal/waf/requests/request.go
Normal file
@@ -0,0 +1,52 @@
|
||||
package requests
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Request interface {
|
||||
// WAFRaw 原始请求
|
||||
WAFRaw() *http.Request
|
||||
|
||||
// WAFRemoteIP 客户端IP
|
||||
WAFRemoteIP() string
|
||||
|
||||
// WAFGetCacheBody 获取缓存中的Body
|
||||
WAFGetCacheBody() []byte
|
||||
|
||||
// WAFSetCacheBody 设置Body
|
||||
WAFSetCacheBody(body []byte)
|
||||
|
||||
// WAFReadBody 读取Body
|
||||
WAFReadBody(max int64) (data []byte, err error)
|
||||
|
||||
// WAFRestoreBody 恢复Body
|
||||
WAFRestoreBody(data []byte)
|
||||
|
||||
// WAFServerId 服务ID
|
||||
WAFServerId() int64
|
||||
|
||||
// WAFClose 关闭当前请求所在的连接
|
||||
WAFClose()
|
||||
|
||||
// WAFOnAction 动作回调
|
||||
WAFOnAction(action any) (goNext bool)
|
||||
|
||||
// WAFFingerprint 读取连接指纹
|
||||
WAFFingerprint() []byte
|
||||
|
||||
// WAFMaxRequestSize 可以检查的最大内容尺寸
|
||||
WAFMaxRequestSize() int64
|
||||
|
||||
// Format 格式化变量
|
||||
Format(varString string) string
|
||||
|
||||
// ProcessResponseHeaders 处理响应Header
|
||||
ProcessResponseHeaders(headers http.Header, status int)
|
||||
|
||||
// DisableAccessLog 在当前请求中不使用访问日志
|
||||
DisableAccessLog()
|
||||
|
||||
// DisableStat 在当前请求中停用统计
|
||||
DisableStat()
|
||||
}
|
||||
15
EdgeNode/internal/waf/requests/response.go
Normal file
15
EdgeNode/internal/waf/requests/response.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package requests
|
||||
|
||||
import "net/http"
|
||||
|
||||
type Response struct {
|
||||
*http.Response
|
||||
|
||||
BodyData []byte
|
||||
}
|
||||
|
||||
func NewResponse(resp *http.Response) *Response {
|
||||
return &Response{
|
||||
Response: resp,
|
||||
}
|
||||
}
|
||||
98
EdgeNode/internal/waf/requests/test_request.go
Normal file
98
EdgeNode/internal/waf/requests/test_request.go
Normal file
@@ -0,0 +1,98 @@
|
||||
// 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 {
|
||||
data, err = io.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 = io.NopCloser(rawReader)
|
||||
}
|
||||
}
|
||||
|
||||
func (this *TestRequest) WAFServerId() int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// WAFClose 关闭当前请求所在的连接
|
||||
func (this *TestRequest) WAFClose() {
|
||||
}
|
||||
|
||||
func (this *TestRequest) Format(s string) string {
|
||||
return s
|
||||
}
|
||||
|
||||
func (this *TestRequest) WAFOnAction(action any) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (this *TestRequest) WAFFingerprint() []byte {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (this *TestRequest) DisableAccessLog() {
|
||||
|
||||
}
|
||||
|
||||
func (this *TestRequest) DisableStat() {
|
||||
|
||||
}
|
||||
|
||||
func (this *TestRequest) ProcessResponseHeaders(headers http.Header, status int) {
|
||||
|
||||
}
|
||||
|
||||
func (this *TestRequest) WAFMaxRequestSize() int64 {
|
||||
return 1 << 20
|
||||
}
|
||||
Reference in New Issue
Block a user