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

Function TestBodyDump_ClientGetsFullResponse

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

Source from the content-addressed store, hash-verified

372}
373
374func 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
406func TestBodyDump_BothLimitsSimultaneous(t *testing.T) {
407 e := echo.New()

Callers

nothing calls this directly

Calls 5

ResponseMethod · 0.95
NewContextMethod · 0.80
ToMiddlewareMethod · 0.65
WriteMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…