Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete unused context in body_limit.go #2483

Merged
merged 3 commits into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) {
aldas marked this conversation as resolved.
Show resolved Hide resolved
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