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

Function TestBodyDump_RequestWithinLimit

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

Source from the content-addressed store, hash-verified

225}
226
227func TestBodyDump_RequestWithinLimit(t *testing.T) {
228 e := echo.New()
229 requestData := "Hello, World!"
230 req := httptest.NewRequest(http.MethodPost, "/", strings.NewReader(requestData))
231 rec := httptest.NewRecorder()
232 c := e.NewContext(req, rec)
233
234 h := func(c *echo.Context) error {
235 body, _ := io.ReadAll(c.Request().Body)
236 return c.String(http.StatusOK, string(body))
237 }
238
239 requestBodyDumped := ""
240 mw, err := BodyDumpConfig{
241 Handler: func(c *echo.Context, reqBody, resBody []byte, err error) {
242 requestBodyDumped = string(reqBody)
243 },
244 MaxRequestBytes: 1 * MB, // 1MB limit
245 MaxResponseBytes: 1 * MB,
246 }.ToMiddleware()
247 assert.NoError(t, err)
248
249 err = mw(h)(c)
250 assert.NoError(t, err)
251 assert.Equal(t, requestData, requestBodyDumped, "Small request should be fully dumped")
252 assert.Equal(t, requestData, rec.Body.String(), "Handler should receive full request")
253}
254
255func TestBodyDump_RequestExceedsLimit(t *testing.T) {
256 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…