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

Function TestBodyLimitAfterDecompressUsesDecodedSize

middleware/body_limit_test.go:71–94  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

69}
70
71func TestBodyLimitAfterDecompressUsesDecodedSize(t *testing.T) {
72 e := echo.New()
73 body := "ok"
74 gz, err := gzipString(body)
75 assert.NoError(t, err)
76 assert.Greater(t, len(gz), len(body))
77
78 req := httptest.NewRequest(http.MethodPost, "/", bytes.NewReader(gz))
79 req.Header.Set(echo.HeaderContentEncoding, GZIPEncoding)
80 rec := httptest.NewRecorder()
81 c := e.NewContext(req, rec)
82
83 err = Decompress()(BodyLimit(int64(len(body)))(func(c *echo.Context) error {
84 body, readErr := io.ReadAll(c.Request().Body)
85 if readErr != nil {
86 return readErr
87 }
88 return c.String(http.StatusOK, string(body))
89 }))(c)
90
91 assert.NoError(t, err)
92 assert.Equal(t, http.StatusOK, rec.Code)
93 assert.Equal(t, body, rec.Body.String())
94}
95
96func TestBodyLimitReader(t *testing.T) {
97 hw := []byte("Hello, World!")

Callers

nothing calls this directly

Calls 7

RequestMethod · 0.95
StringMethod · 0.95
gzipStringFunction · 0.85
DecompressFunction · 0.85
BodyLimitFunction · 0.85
SetMethod · 0.80
NewContextMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…