(t *testing.T)
| 404 | } |
| 405 | |
| 406 | func TestBodyDump_BothLimitsSimultaneous(t *testing.T) { |
| 407 | e := echo.New() |
| 408 | largeRequest := strings.Repeat("Q", 2*1024) |
| 409 | largeResponse := strings.Repeat("R", 2*1024) |
| 410 | req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(largeRequest)) |
| 411 | rec := httptest.NewRecorder() |
| 412 | c := e.NewContext(req, rec) |
| 413 | |
| 414 | h := func(c *echo.Context) error { |
| 415 | io.ReadAll(c.Request().Body) // Consume request |
| 416 | return c.String(http.StatusOK, largeResponse) |
| 417 | } |
| 418 | |
| 419 | requestBodyDumped := "" |
| 420 | responseBodyDumped := "" |
| 421 | limit := int64(1024) |
| 422 | mw, err := BodyDumpConfig{ |
| 423 | Handler: func(c *echo.Context, reqBody, resBody []byte, err error) { |
| 424 | requestBodyDumped = string(reqBody) |
| 425 | responseBodyDumped = string(resBody) |
| 426 | }, |
| 427 | MaxRequestBytes: limit, |
| 428 | MaxResponseBytes: limit, |
| 429 | }.ToMiddleware() |
| 430 | assert.NoError(t, err) |
| 431 | |
| 432 | err = mw(h)(c) |
| 433 | assert.NoError(t, err) |
| 434 | assert.Equal(t, int(limit), len(requestBodyDumped), "Request dump should be limited") |
| 435 | assert.Equal(t, int(limit), len(responseBodyDumped), "Response dump should be limited") |
| 436 | } |
| 437 | |
| 438 | func TestBodyDump_DefaultConfig(t *testing.T) { |
| 439 | e := echo.New() |
nothing calls this directly
no test coverage detected
searching dependent graphs…