(t *testing.T)
| 341 | } |
| 342 | |
| 343 | func 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 | |
| 374 | func TestBodyDump_ClientGetsFullResponse(t *testing.T) { |
| 375 | e := echo.New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…