MCPcopy
hub / github.com/labstack/echo / TestBodyDump_ResponseExceedsLimit

Function TestBodyDump_ResponseExceedsLimit

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

Source from the content-addressed store, hash-verified

341}
342
343func TestBodyDump_ResponseExceedsLimit(t *testing.T) {
344 e := echo.New()
345 largeResponse := strings.Repeat("X", 2*1024) // 2KB
346 req := httptest.NewRequest(http.MethodGet, "/", nil)
347 rec := httptest.NewRecorder()
348 c := e.NewContext(req, rec)
349
350 h := func(c *echo.Context) error {
351 return c.String(http.StatusOK, largeResponse)
352 }
353
354 responseBodyDumped := ""
355 limit := int64(1024) // 1KB limit
356 mw, err := BodyDumpConfig{
357 Handler: func(c *echo.Context, reqBody, resBody []byte, err error) {
358 responseBodyDumped = string(resBody)
359 },
360 MaxRequestBytes: 1 * MB,
361 MaxResponseBytes: limit,
362 }.ToMiddleware()
363 assert.NoError(t, err)
364
365 err = mw(h)(c)
366 assert.NoError(t, err)
367 // Dump should be truncated
368 assert.Equal(t, int(limit), len(responseBodyDumped), "Dumped response should be truncated to limit")
369 assert.Equal(t, strings.Repeat("X", 1024), responseBodyDumped)
370 // Client should still receive full response!
371 assert.Equal(t, largeResponse, rec.Body.String(), "Client must receive full response despite dump truncation")
372}
373
374func TestBodyDump_ClientGetsFullResponse(t *testing.T) {
375 e := echo.New()

Callers

nothing calls this directly

Calls 3

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…