MCPcopy Index your code
hub / github.com/labstack/echo / TestBodyDump_RequestExceedsLimit

Function TestBodyDump_RequestExceedsLimit

middleware/body_dump_test.go:255–285  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

253}
254
255func TestBodyDump_RequestExceedsLimit(t *testing.T) {
256 e := echo.New()
257 // Create 2KB of data but limit to 1KB
258 largeData := strings.Repeat("A", 2*1024)
259 req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(largeData))
260 rec := httptest.NewRecorder()
261 c := e.NewContext(req, rec)
262
263 h := func(c *echo.Context) error {
264 body, _ := io.ReadAll(c.Request().Body)
265 return c.String(http.StatusOK, string(body))
266 }
267
268 requestBodyDumped := ""
269 limit := int64(1024) // 1KB limit
270 mw, err := BodyDumpConfig{
271 Handler: func(c *echo.Context, reqBody, resBody []byte, err error) {
272 requestBodyDumped = string(reqBody)
273 },
274 MaxRequestBytes: limit,
275 MaxResponseBytes: 1 * MB,
276 }.ToMiddleware()
277 assert.NoError(t, err)
278
279 err = mw(h)(c)
280 assert.NoError(t, err)
281 assert.Equal(t, int(limit), len(requestBodyDumped), "Dumped request should be truncated to limit")
282 assert.Equal(t, strings.Repeat("A", 1024), requestBodyDumped, "Dumped data should match first N bytes")
283 // Handler should receive truncated data (what was dumped)
284 assert.Equal(t, strings.Repeat("A", 1024), rec.Body.String())
285}
286
287func TestBodyDump_RequestAtExactLimit(t *testing.T) {
288 e := echo.New()

Callers

nothing calls this directly

Calls 4

RequestMethod · 0.95
StringMethod · 0.95
NewContextMethod · 0.80
ToMiddlewareMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…