(t *testing.T)
| 372 | } |
| 373 | |
| 374 | func TestBodyDump_ClientGetsFullResponse(t *testing.T) { |
| 375 | e := echo.New() |
| 376 | // This is critical - even when dump is limited, client gets everything |
| 377 | largeResponse := strings.Repeat("DATA", 500) // 2KB |
| 378 | req := httptest.NewRequest(http.MethodGet, "/", nil) |
| 379 | rec := httptest.NewRecorder() |
| 380 | c := e.NewContext(req, rec) |
| 381 | |
| 382 | h := func(c *echo.Context) error { |
| 383 | // Write response in chunks to test incremental writes |
| 384 | for range 4 { |
| 385 | c.Response().Write([]byte(strings.Repeat("DATA", 125))) |
| 386 | } |
| 387 | return nil |
| 388 | } |
| 389 | |
| 390 | responseBodyDumped := "" |
| 391 | mw, err := BodyDumpConfig{ |
| 392 | Handler: func(c *echo.Context, reqBody, resBody []byte, err error) { |
| 393 | responseBodyDumped = string(resBody) |
| 394 | }, |
| 395 | MaxRequestBytes: 1 * MB, |
| 396 | MaxResponseBytes: 512, // Very small limit |
| 397 | }.ToMiddleware() |
| 398 | assert.NoError(t, err) |
| 399 | |
| 400 | err = mw(h)(c) |
| 401 | assert.NoError(t, err) |
| 402 | assert.Equal(t, 512, len(responseBodyDumped), "Dump should be limited") |
| 403 | assert.Equal(t, largeResponse, rec.Body.String(), "Client must get full response") |
| 404 | } |
| 405 | |
| 406 | func TestBodyDump_BothLimitsSimultaneous(t *testing.T) { |
| 407 | e := echo.New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…