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

Function TestBodyDump_BothLimitsSimultaneous

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

Source from the content-addressed store, hash-verified

404}
405
406func 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
438func TestBodyDump_DefaultConfig(t *testing.T) {
439 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…