Problem
Body limit middleware must manually parse c.Header("content-length") with strconv.ParseInt to check declared body size. A typed accessor avoids boilerplate and returns -1 for missing/invalid values (standard convention).
Unblocks
Change
// context_request.go
func (c *Context) ContentLength() int64 {
cl := c.Header("content-length")
if cl == "" {
return -1
}
n, err := strconv.ParseInt(cl, 10, 64)
if err != nil || n < 0 {
return -1
}
return n
}
Performance
Zero cost when not called. Parses header on demand (no caching needed — called at most once per request by body-limit middleware).
Files
Problem
Body limit middleware must manually parse
c.Header("content-length")withstrconv.ParseIntto check declared body size. A typed accessor avoids boilerplate and returns -1 for missing/invalid values (standard convention).Unblocks
Change
Performance
Zero cost when not called. Parses header on demand (no caching needed — called at most once per request by body-limit middleware).
Files
context_request.go