• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-server / 1927964654

15 Jul 2025 01:18PM UTC coverage: 65.511% (+0.06%) from 65.454%
1927964654

Pull #783

gitlab-ci

bahaa-ghazal
feat: Integrate requestsize middleware into useradm

Title: None
Signed-off-by: Bahaa Aldeen Ghazal <bahaa.ghazal@northern.tech>
Pull Request #783: feat: Implemented gin request body size limiter middleware

131 of 139 new or added lines in 17 files covered. (94.24%)

6 existing lines in 1 file now uncovered.

32173 of 49111 relevant lines covered (65.51%)

1.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/backend/pkg/requestsize/middleware.go
1
package requestsize
2

3
import (
4
        "net/http"
5

6
        "github.com/gin-gonic/gin"
7

8
        "github.com/mendersoftware/mender-server/pkg/rest.utils"
9
)
10

11
func Middleware(size int64) gin.HandlerFunc {
9✔
12
        if size < 0 {
9✔
NEW
13
                panic("requestsize Middleware initialized with negativ size")
×
14
        }
15
        tooLargeErr := http.MaxBytesError{
9✔
16
                Limit: size,
9✔
17
        }
9✔
18
        return func(c *gin.Context) {
18✔
19
                // if the Content-Length in header and is greater than size limit
9✔
20
                if c.Request.ContentLength > int64(size) {
10✔
21
                        rest.RenderError(c, http.StatusRequestEntityTooLarge, &tooLargeErr)
1✔
22
                        c.Abort()
1✔
23
                        return
1✔
24
                }
1✔
25
                // wrapping a nil body with MaxBytesReader causes a nil pointer dereference panic
26
                // when calling c.ShouldBindJSON()
27
                if c.Request.Body != nil {
18✔
28
                        c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, size)
9✔
29
                }
9✔
30

31
                c.Next()
9✔
32
        }
33
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc