mirror of
https://github.com/labstack/echo.git
synced 2024-11-24 08:22:21 +02:00
delete unused context in body_limit.go (#2483)
* delete unused context in body_limit.go --------- Co-authored-by: mobinanoori018 <mobinanoori21@gmail.com>
This commit is contained in:
parent
4598a4a745
commit
3f8ae15b57
@ -23,9 +23,8 @@ type (
|
|||||||
|
|
||||||
limitedReader struct {
|
limitedReader struct {
|
||||||
BodyLimitConfig
|
BodyLimitConfig
|
||||||
reader io.ReadCloser
|
reader io.ReadCloser
|
||||||
read int64
|
read int64
|
||||||
context echo.Context
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -80,7 +79,7 @@ func BodyLimitWithConfig(config BodyLimitConfig) echo.MiddlewareFunc {
|
|||||||
|
|
||||||
// Based on content read
|
// Based on content read
|
||||||
r := pool.Get().(*limitedReader)
|
r := pool.Get().(*limitedReader)
|
||||||
r.Reset(req.Body, c)
|
r.Reset(req.Body)
|
||||||
defer pool.Put(r)
|
defer pool.Put(r)
|
||||||
req.Body = r
|
req.Body = r
|
||||||
|
|
||||||
@ -102,9 +101,8 @@ func (r *limitedReader) Close() error {
|
|||||||
return r.reader.Close()
|
return r.reader.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *limitedReader) Reset(reader io.ReadCloser, context echo.Context) {
|
func (r *limitedReader) Reset(reader io.ReadCloser) {
|
||||||
r.reader = reader
|
r.reader = reader
|
||||||
r.context = context
|
|
||||||
r.read = 0
|
r.read = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,9 +56,6 @@ func TestBodyLimit(t *testing.T) {
|
|||||||
|
|
||||||
func TestBodyLimitReader(t *testing.T) {
|
func TestBodyLimitReader(t *testing.T) {
|
||||||
hw := []byte("Hello, World!")
|
hw := []byte("Hello, World!")
|
||||||
e := echo.New()
|
|
||||||
req := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(hw))
|
|
||||||
rec := httptest.NewRecorder()
|
|
||||||
|
|
||||||
config := BodyLimitConfig{
|
config := BodyLimitConfig{
|
||||||
Skipper: DefaultSkipper,
|
Skipper: DefaultSkipper,
|
||||||
@ -68,7 +65,6 @@ func TestBodyLimitReader(t *testing.T) {
|
|||||||
reader := &limitedReader{
|
reader := &limitedReader{
|
||||||
BodyLimitConfig: config,
|
BodyLimitConfig: config,
|
||||||
reader: io.NopCloser(bytes.NewReader(hw)),
|
reader: io.NopCloser(bytes.NewReader(hw)),
|
||||||
context: e.NewContext(req, rec),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// read all should return ErrStatusRequestEntityTooLarge
|
// read all should return ErrStatusRequestEntityTooLarge
|
||||||
@ -78,7 +74,7 @@ func TestBodyLimitReader(t *testing.T) {
|
|||||||
|
|
||||||
// reset reader and read two bytes must succeed
|
// reset reader and read two bytes must succeed
|
||||||
bt := make([]byte, 2)
|
bt := make([]byte, 2)
|
||||||
reader.Reset(io.NopCloser(bytes.NewReader(hw)), e.NewContext(req, rec))
|
reader.Reset(io.NopCloser(bytes.NewReader(hw)))
|
||||||
n, err := reader.Read(bt)
|
n, err := reader.Read(bt)
|
||||||
assert.Equal(t, 2, n)
|
assert.Equal(t, 2, n)
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
|
Loading…
Reference in New Issue
Block a user