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

jeffotoni / quick / 265

19 Mar 2025 09:26PM UTC coverage: 52.375% (-0.2%) from 52.567%
265

push

circleci

jeffotoni
Merge remote-tracking branch 'origin/docs/middleware'

0 of 19 new or added lines in 1 file covered. (0.0%)

3 existing lines in 3 files now uncovered.

2713 of 5180 relevant lines covered (52.37%)

1929.46 hits per line

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

0.0
/example/middleware/maxbody/max.bytes.reader/main.go
1
package main
2

3
import (
4
        "io"
5
        "log"
6
        "net/http"
7

8
        "github.com/jeffotoni/quick"
9
)
10

11
const maxBodySize = 1024 // 1KB
12

13
// Start the server and apply request body size limit middleware
NEW
14
func main() {
×
NEW
15
        q := quick.New()
×
NEW
16

×
NEW
17
        // Define route with extra validation using MaxBytesReader
×
NEW
18
        q.Post("/v1/user/maxbody/max", func(c *quick.Ctx) error {
×
NEW
19
                c.Set("Content-Type", "application/json")
×
NEW
20

×
NEW
21
                // Apply MaxBytesReader to prevent oversized payloads
×
NEW
22
                c.Request.Body = quick.MaxBytesReader(c.Response, c.Request.Body, maxBodySize)
×
NEW
23

×
NEW
24
                // Securely read the request body
×
NEW
25
                body, err := io.ReadAll(c.Request.Body)
×
NEW
26
                if err != nil {
×
NEW
27
                        log.Printf("Error reading request body: %v", err)
×
NEW
28
                        return c.Status(http.StatusRequestEntityTooLarge).String("Request body too large")
×
NEW
29
                }
×
NEW
30
                return c.Status(http.StatusOK).Send(body)
×
31
        })
32

NEW
33
        log.Println("Server running at http://0.0.0.0:8080")
×
NEW
34
        log.Fatal(q.Listen("0.0.0.0:8080"))
×
35
}
36

37
// $ curl -X POST http://0.0.0.0:8080/v1/user/maxbody/max \
38
//      -H "Content-Type: application/json" \
39
//      --data-binary @<(head -c 2048 </dev/zero | tr '\0' 'A')
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

© 2026 Coveralls, Inc