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

jeffotoni / quick / 225

06 Mar 2025 10:06PM UTC coverage: 48.491% (-0.4%) from 48.866%
225

push

circleci

jeffotoni
Merge remote-tracking branch 'origin/example/http'

more examples

0 of 73 new or added lines in 10 files covered. (0.0%)

1832 of 3778 relevant lines covered (48.49%)

2641.88 hits per line

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

0.0
/example/quick.http.client/custom.http.client/main.go
1
package main
2

3
import (
4
        "context"
5
        "crypto/tls"
6
        "fmt"
7
        "log"
8
        "net/http"
9
        "net/http/cookiejar"
10
        "time"
11

12
        "github.com/jeffotoni/quick/http/client"
13
)
14

15
func main() {
×
16
        // Creating a CookieJar to manage cookies automatically.
×
17
        jar, _ := cookiejar.New(nil)
×
18

×
19
        // Creating a fully custom *http.Client.
×
20
        customHTTPClient := &http.Client{
×
21
                Timeout: 10 * time.Second, // Sets a global timeout of 10 seconds.
×
22
                Jar:     jar,              // Uses a CookieJar to store cookies.
×
23
                CheckRedirect: func(req *http.Request, via []*http.Request) error {
×
24
                        // Allows up to 3 redirects.
×
25
                        if len(via) >= 3 {
×
26
                                return http.ErrUseLastResponse
×
27
                        }
×
28
                        return nil
×
29
                },
30
                Transport: &http.Transport{
31
                        Proxy: http.ProxyFromEnvironment,
32
                        TLSClientConfig: &tls.Config{
33
                                InsecureSkipVerify: true, // Allows insecure TLS (not recommended for production).
34
                                MinVersion:         tls.VersionTLS12,
35
                        },
36
                        MaxIdleConns:        50,    // Maximum idle connections.
37
                        MaxConnsPerHost:     30,    // Max simultaneous connections per host.
38
                        MaxIdleConnsPerHost: 10,    // Max idle connections per host.
39
                        DisableKeepAlives:   false, // Enables keep-alive.
40
                },
41
        }
42

43
        // Creating a quick client using the custom *http.Client.
44
        cClient := client.New(
×
45
                client.WithCustomHTTPClient(customHTTPClient), // Uses the pre-configured HTTP client.
×
46
                client.WithContext(context.Background()),      // Sets a request context.
×
47
                client.WithHeaders(map[string]string{
×
48
                        "Content-Type":  "application/json",
×
49
                        "Authorization": "Bearer YOUR_ACCESS_TOKEN",
×
50
                }),
×
51
                // Enables retry for specific HTTP status codes using the new RetryConfig.
×
52
                client.WithRetry(client.RetryConfig{
×
53
                        MaxRetries: 3,                         // Maximum number of retries.
×
54
                        Delay:      1 * time.Second,           // Delay between attempts.
×
55
                        UseBackoff: true,                      // Use exponential backoff.
×
56
                        Statuses:   []int{500, 502, 503, 504}, // HTTP statuses for retry.
×
NEW
57
                        FailoverURLs: []string{
×
NEW
58
                                "http://backup1",
×
NEW
59
                                "https://httpbin_error.org/post",
×
NEW
60
                                "http://hosterror"},
×
NEW
61
                        EnableLog: true, // Enable logger.
×
62
                }),
×
63
        )
×
64

×
65
        // Performing a GET request.
×
66
        resp, err := cClient.Get("https://httpbin.org/get")
×
67
        if err != nil {
×
68
                log.Fatalf("GET request failed: %v", err)
×
69
        }
×
70
        fmt.Println("GET Response:", string(resp.Body))
×
71

×
72
        // Performing a POST request.
×
73
        data := map[string]string{"name": "QuickFramework", "version": "1.0"}
×
74
        resp, err = cClient.Post("https://httpbin.org/post", data)
×
75
        if err != nil {
×
76
                log.Fatalf("POST request failed: %v", err)
×
77
        }
×
78
        fmt.Println("POST Response:", string(resp.Body))
×
79
}
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