Files
seaweedfs/weed/s3api/request_body_test.go
T
Chris Lu 93d4a6aefd s3: drain request body before error response (#11334)
* s3: drain request body before error response

* s3: keep oversized request bodies drainable
2026-09-15 13:09:07 -07:00

25 lines
530 B
Go

package s3api
import (
"io"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestReadRequestBodyLeavesOversizedBodyDrainable(t *testing.T) {
req := httptest.NewRequest(http.MethodPost, "/", nil)
req.Body = io.NopCloser(strings.NewReader("abcdef"))
body, err := readRequestBody(req, 3)
remaining, readErr := io.ReadAll(req.Body)
assert.ErrorIs(t, err, errRequestBodyTooLarge)
assert.Nil(t, body)
assert.NoError(t, readErr)
assert.Equal(t, "ef", string(remaining))
}