Skip to content

Commit

Permalink
delete unused context in body_limit.go (#2483)
Browse files Browse the repository at this point in the history
* delete unused context in body_limit.go

---------

Co-authored-by: mobinanoori018 <mobinanoori21@gmail.com>
  • Loading branch information
mobinanoorii and mobinanoori018 authored Jul 21, 2023
1 parent 4598a4a commit 3f8ae15
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
10 changes: 4 additions & 6 deletions middleware/body_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ type (

limitedReader struct {
BodyLimitConfig
reader io.ReadCloser
read int64
context echo.Context
reader io.ReadCloser
read int64
}
)

Expand Down Expand Up @@ -80,7 +79,7 @@ func BodyLimitWithConfig(config BodyLimitConfig) echo.MiddlewareFunc {

// Based on content read
r := pool.Get().(*limitedReader)
r.Reset(req.Body, c)
r.Reset(req.Body)
defer pool.Put(r)
req.Body = r

Expand All @@ -102,9 +101,8 @@ func (r *limitedReader) Close() error {
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.context = context
r.read = 0
}

Expand Down
6 changes: 1 addition & 5 deletions middleware/body_limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ func TestBodyLimit(t *testing.T) {

func TestBodyLimitReader(t *testing.T) {
hw := []byte("Hello, World!")
e := echo.New()
req := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(hw))
rec := httptest.NewRecorder()

config := BodyLimitConfig{
Skipper: DefaultSkipper,
Expand All @@ -68,7 +65,6 @@ func TestBodyLimitReader(t *testing.T) {
reader := &limitedReader{
BodyLimitConfig: config,
reader: io.NopCloser(bytes.NewReader(hw)),
context: e.NewContext(req, rec),
}

// read all should return ErrStatusRequestEntityTooLarge
Expand All @@ -78,7 +74,7 @@ func TestBodyLimitReader(t *testing.T) {

// reset reader and read two bytes must succeed
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)
assert.Equal(t, 2, n)
assert.Equal(t, nil, err)
Expand Down

0 comments on commit 3f8ae15

Please sign in to comment.