MCPcopy Create free account
hub / github.com/compozy/agh / requestBodyLimitMiddleware

Function requestBodyLimitMiddleware

internal/api/httpapi/middleware.go:254–272  ·  view source on GitHub ↗
(maxBytes int64)

Source from the content-addressed store, hash-verified

252}
253
254func requestBodyLimitMiddleware(maxBytes int64) gin.HandlerFunc {
255 return func(c *gin.Context) {
256 if maxBytes <= 0 || c.Request == nil || c.Request.Body == nil || c.Request.Body == http.NoBody {
257 c.Next()
258 return
259 }
260 if !strings.HasPrefix(c.Request.URL.Path, "/api/") {
261 c.Next()
262 return
263 }
264 if c.Request.ContentLength > maxBytes {
265 core.RespondError(c, http.StatusRequestEntityTooLarge, errRequestBodyTooLarge, false)
266 c.Abort()
267 return
268 }
269 c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, maxBytes)
270 c.Next()
271 }
272}
273
274func loopbackAPIGuard(boundHost string) gin.HandlerFunc {
275 return loopbackGuard(boundHost, errLoopbackAPIRequired, true)

Callers 2

newTestRouterFunction · 0.85
ensureEngineMethod · 0.85

Calls 1

RespondErrorFunction · 0.92

Tested by 1

newTestRouterFunction · 0.68