优化代码

This commit is contained in:
GoEdgeLab
2022-04-08 16:11:05 +08:00
parent 9d0467fe8a
commit bf604baf3d
6 changed files with 20 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package checkpoints
import ( import (
"github.com/TeaOSLab/EdgeNode/internal/waf/requests" "github.com/TeaOSLab/EdgeNode/internal/waf/requests"
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
) )
@@ -28,7 +29,7 @@ func (this *RequestAllCheckpoint) RequestValue(req requests.Request, param strin
var bodyData = req.WAFGetCacheBody() var bodyData = req.WAFGetCacheBody()
if len(bodyData) == 0 { if len(bodyData) == 0 {
data, err := req.WAFReadBody(int64(32 * 1024 * 1024)) // read 32m bytes data, err := req.WAFReadBody(utils.MaxBodySize) // read body
if err != nil { if err != nil {
return "", err, nil return "", err, nil
} }

View File

@@ -2,6 +2,7 @@ package checkpoints
import ( import (
"github.com/TeaOSLab/EdgeNode/internal/waf/requests" "github.com/TeaOSLab/EdgeNode/internal/waf/requests"
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
) )
@@ -23,7 +24,7 @@ func (this *RequestBodyCheckpoint) RequestValue(req requests.Request, param stri
var bodyData = req.WAFGetCacheBody() var bodyData = req.WAFGetCacheBody()
if len(bodyData) == 0 { if len(bodyData) == 0 {
data, err := req.WAFReadBody(int64(32 * 1024 * 1024)) // read 32m bytes data, err := req.WAFReadBody(utils.MaxBodySize) // read body
if err != nil { if err != nil {
return "", err, nil return "", err, nil
} }

View File

@@ -2,6 +2,7 @@ package checkpoints
import ( import (
"github.com/TeaOSLab/EdgeNode/internal/waf/requests" "github.com/TeaOSLab/EdgeNode/internal/waf/requests"
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
"net/url" "net/url"
) )
@@ -24,7 +25,7 @@ func (this *RequestFormArgCheckpoint) RequestValue(req requests.Request, param s
var bodyData = req.WAFGetCacheBody() var bodyData = req.WAFGetCacheBody()
if len(bodyData) == 0 { if len(bodyData) == 0 {
data, err := req.WAFReadBody(int64(32 * 1024 * 1024)) // read 32m bytes data, err := req.WAFReadBody(utils.MaxBodySize) // read body
if err != nil { if err != nil {
return "", err, nil return "", err, nil
} }

View File

@@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"github.com/TeaOSLab/EdgeNode/internal/utils" "github.com/TeaOSLab/EdgeNode/internal/utils"
"github.com/TeaOSLab/EdgeNode/internal/waf/requests" "github.com/TeaOSLab/EdgeNode/internal/waf/requests"
wafutils "github.com/TeaOSLab/EdgeNode/internal/waf/utils"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
"strings" "strings"
) )
@@ -16,7 +17,7 @@ type RequestJSONArgCheckpoint struct {
func (this *RequestJSONArgCheckpoint) RequestValue(req requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) { func (this *RequestJSONArgCheckpoint) RequestValue(req requests.Request, param string, options maps.Map) (value interface{}, sysErr error, userErr error) {
var bodyData = req.WAFGetCacheBody() var bodyData = req.WAFGetCacheBody()
if len(bodyData) == 0 { if len(bodyData) == 0 {
data, err := req.WAFReadBody(int64(32 * 1024 * 1024)) // read 32m bytes data, err := req.WAFReadBody(wafutils.MaxBodySize) // read body
if err != nil { if err != nil {
return "", err, nil return "", err, nil
} }

View File

@@ -3,6 +3,7 @@ package checkpoints
import ( import (
"bytes" "bytes"
"github.com/TeaOSLab/EdgeNode/internal/waf/requests" "github.com/TeaOSLab/EdgeNode/internal/waf/requests"
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
"github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/lists"
"github.com/iwind/TeaGo/maps" "github.com/iwind/TeaGo/maps"
"io/ioutil" "io/ioutil"
@@ -38,7 +39,7 @@ func (this *RequestUploadCheckpoint) RequestValue(req requests.Request, param st
if req.WAFRaw().MultipartForm == nil { if req.WAFRaw().MultipartForm == nil {
var bodyData = req.WAFGetCacheBody() var bodyData = req.WAFGetCacheBody()
if len(bodyData) == 0 { if len(bodyData) == 0 {
data, err := req.WAFReadBody(32 * 1024 * 1024) data, err := req.WAFReadBody(utils.MaxBodySize)
if err != nil { if err != nil {
sysErr = err sysErr = err
return return
@@ -51,7 +52,7 @@ func (this *RequestUploadCheckpoint) RequestValue(req requests.Request, param st
oldBody := req.WAFRaw().Body oldBody := req.WAFRaw().Body
req.WAFRaw().Body = ioutil.NopCloser(bytes.NewBuffer(bodyData)) req.WAFRaw().Body = ioutil.NopCloser(bytes.NewBuffer(bodyData))
err := req.WAFRaw().ParseMultipartForm(32 * 1024 * 1024) err := req.WAFRaw().ParseMultipartForm(utils.MaxBodySize)
// 还原 // 还原
req.WAFRaw().Body = oldBody req.WAFRaw().Body = oldBody

View File

@@ -0,0 +1,9 @@
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
package utils
import "github.com/TeaOSLab/EdgeNode/internal/utils/sizes"
const (
MaxBodySize = 4 * sizes.M
)