优化代码

This commit is contained in:
GoEdgeLab
2022-08-04 11:34:06 +08:00
parent 9c00b07d9e
commit bcd6784a8f
31 changed files with 66 additions and 82 deletions
+3 -3
View File
@@ -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)
}
+2 -2
View File
@@ -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)
}
+3 -3
View File
@@ -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)
}