mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2026-01-06 07:45:47 +08:00
优化代码
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -111,7 +110,7 @@ func (this *BlockAction) Perform(waf *WAF, group *RuleGroup, set *RuleSet, reque
|
||||
path = Tea.Root + string(os.PathSeparator) + path
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
logs.Error(err)
|
||||
return false
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"strings"
|
||||
@@ -28,7 +28,7 @@ func TestRequestAllCheckpoint_RequestValue(t *testing.T) {
|
||||
t.Log(v)
|
||||
t.Log(types.String(v))
|
||||
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
body, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func TestRequestAllCheckpoint_RequestValue_Max(t *testing.T) {
|
||||
}
|
||||
t.Log("value bytes:", len(types.String(value)))
|
||||
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
body, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -19,7 +19,7 @@ func TestRequestBodyCheckpoint_RequestValue(t *testing.T) {
|
||||
checkpoint := new(RequestBodyCheckpoint)
|
||||
t.Log(checkpoint.RequestValue(req, "", nil, 1))
|
||||
|
||||
body, err := ioutil.ReadAll(rawReq.Body)
|
||||
body, err := io.ReadAll(rawReq.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func TestRequestBodyCheckpoint_RequestValue_Max(t *testing.T) {
|
||||
}
|
||||
t.Log("value bytes:", len(types.String(value)))
|
||||
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
body, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package checkpoints
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"testing"
|
||||
@@ -24,7 +24,7 @@ func TestRequestFormArgCheckpoint_RequestValue(t *testing.T) {
|
||||
t.Log(checkpoint.RequestValue(req, "Hello", nil, 1))
|
||||
t.Log(checkpoint.RequestValue(req, "encoded", nil, 1))
|
||||
|
||||
body, err := ioutil.ReadAll(req.WAFRaw().Body)
|
||||
body, err := io.ReadAll(req.WAFRaw().Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package checkpoints
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
@@ -31,7 +31,7 @@ func TestRequestJSONArgCheckpoint_RequestValue_Map(t *testing.T) {
|
||||
t.Log(checkpoint.RequestValue(req, "books", nil, 1))
|
||||
t.Log(checkpoint.RequestValue(req, "books.1", nil, 1))
|
||||
|
||||
body, err := ioutil.ReadAll(req.WAFRaw().Body)
|
||||
body, err := io.ReadAll(req.WAFRaw().Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func TestRequestJSONArgCheckpoint_RequestValue_Array(t *testing.T) {
|
||||
t.Log(checkpoint.RequestValue(req, "0.books", nil, 1))
|
||||
t.Log(checkpoint.RequestValue(req, "0.books.1", nil, 1))
|
||||
|
||||
body, err := ioutil.ReadAll(req.WAFRaw().Body)
|
||||
body, err := io.ReadAll(req.WAFRaw().Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -91,7 +91,7 @@ func TestRequestJSONArgCheckpoint_RequestValue_Error(t *testing.T) {
|
||||
t.Log(checkpoint.RequestValue(req, "0.books", nil, 1))
|
||||
t.Log(checkpoint.RequestValue(req, "0.books.1", nil, 1))
|
||||
|
||||
body, err := ioutil.ReadAll(req.WAFRaw().Body)
|
||||
body, err := io.ReadAll(req.WAFRaw().Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/utils"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
@@ -51,7 +51,7 @@ func (this *RequestUploadCheckpoint) RequestValue(req requests.Request, param st
|
||||
defer req.WAFRestoreBody(data)
|
||||
}
|
||||
oldBody := req.WAFRaw().Body
|
||||
req.WAFRaw().Body = ioutil.NopCloser(bytes.NewBuffer(bodyData))
|
||||
req.WAFRaw().Body = io.NopCloser(bytes.NewBuffer(bodyData))
|
||||
|
||||
err := req.WAFRaw().ParseMultipartForm(utils.MaxBodySize)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ package checkpoints
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"testing"
|
||||
@@ -94,7 +94,7 @@ func TestRequestUploadCheckpoint_RequestValue(t *testing.T) {
|
||||
t.Log(checkpoint.RequestValue(req, "name", nil, 1))
|
||||
t.Log(checkpoint.RequestValue(req, "ext", nil, 1))
|
||||
|
||||
data, err := ioutil.ReadAll(req.WAFRaw().Body)
|
||||
data, err := io.ReadAll(req.WAFRaw().Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
)
|
||||
|
||||
// ResponseBodyCheckpoint ${responseBody}
|
||||
@@ -33,7 +33,7 @@ func (this *ResponseBodyCheckpoint) ResponseValue(req requests.Request, resp *re
|
||||
value = string(resp.BodyData)
|
||||
return
|
||||
}
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
sysErr = err
|
||||
return
|
||||
@@ -41,7 +41,7 @@ func (this *ResponseBodyCheckpoint) ResponseValue(req requests.Request, resp *re
|
||||
resp.BodyData = body
|
||||
_ = resp.Body.Close()
|
||||
value = body
|
||||
resp.Body = ioutil.NopCloser(bytes.NewBuffer(body))
|
||||
resp.Body = io.NopCloser(bytes.NewBuffer(body))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package checkpoints
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/TeaOSLab/EdgeNode/internal/waf/requests"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
@@ -13,7 +13,7 @@ func TestResponseBodyCheckpoint_ResponseValue(t *testing.T) {
|
||||
resp.StatusCode = 200
|
||||
resp.Header = http.Header{}
|
||||
resp.Header.Set("Hello", "World")
|
||||
resp.Body = ioutil.NopCloser(bytes.NewBuffer([]byte("Hello, World")))
|
||||
resp.Body = io.NopCloser(bytes.NewBuffer([]byte("Hello, World")))
|
||||
|
||||
checkpoint := new(ResponseBodyCheckpoint)
|
||||
t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1))
|
||||
@@ -21,7 +21,7 @@ func TestResponseBodyCheckpoint_ResponseValue(t *testing.T) {
|
||||
t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1))
|
||||
t.Log(checkpoint.ResponseValue(nil, resp, "", nil, 1))
|
||||
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
data, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ package requests
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
)
|
||||
@@ -48,7 +47,7 @@ func (this *TestRequest) WAFRemoteIP() string {
|
||||
|
||||
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))
|
||||
data, err = io.ReadAll(io.LimitReader(this.req.Body, max))
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -58,7 +57,7 @@ func (this *TestRequest) WAFRestoreBody(data []byte) {
|
||||
rawReader := bytes.NewBuffer(data)
|
||||
buf := make([]byte, 1024)
|
||||
_, _ = io.CopyBuffer(rawReader, this.req.Body, buf)
|
||||
this.req.Body = ioutil.NopCloser(rawReader)
|
||||
this.req.Body = io.NopCloser(rawReader)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"github.com/iwind/TeaGo/files"
|
||||
"github.com/iwind/TeaGo/types"
|
||||
"gopkg.in/yaml.v3"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
@@ -315,7 +315,7 @@ func (this *WAF) Save(path string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ioutil.WriteFile(path, data, 0644)
|
||||
return os.WriteFile(path, data, 0644)
|
||||
}
|
||||
|
||||
func (this *WAF) ContainsGroupCode(code string) bool {
|
||||
|
||||
Reference in New Issue
Block a user