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

go-ap / client / #56

23 Jun 2026 05:14PM UTC coverage: 80.519% (-0.7%) from 81.206%
#56

push

sourcehut

mariusor
Disable unused lint

1054 of 1309 relevant lines covered (80.52%)

7.52 hits per line

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

88.68
/debug/debug.go
1
package debug
2

3
import (
4
        "net/http"
5
        "net/http/httputil"
6
        "os"
7
        "path/filepath"
8
        "strings"
9
        "time"
10
)
11

12
type OptionFn func(transport *Transport) error
13

14
func WithTransport(tr http.RoundTripper) OptionFn {
4✔
15
        return func(h *Transport) error {
8✔
16
                h.Base = tr
4✔
17
                return nil
4✔
18
        }
4✔
19
}
20

21
func WithPath(where string) OptionFn {
6✔
22
        return func(tr *Transport) error {
12✔
23
                tr.where = where
6✔
24
                return nil
6✔
25
        }
6✔
26
}
27

28
// New returns a RoundTripper that dumps the request/response pair
29
// to disk to the "where" directory
30
// It needs to be used as a base transport if used to debug the headers produced by the
31
// OAuth2 or HTTP-Signatures authorization transports.
32
func New(fn ...OptionFn) http.RoundTripper {
4✔
33
        tr := Transport{}
4✔
34
        for _, initFn := range fn {
8✔
35
                _ = initFn(&tr)
4✔
36
        }
4✔
37
        if tr.Base == nil {
7✔
38
                tr.Base = http.DefaultTransport
3✔
39
        }
3✔
40

41
        maybeDir, err := os.Stat(tr.where)
4✔
42
        if err != nil {
5✔
43
                return tr.Base
1✔
44
        }
1✔
45
        if !maybeDir.IsDir() {
4✔
46
                return tr.Base
1✔
47
        }
1✔
48
        return &tr
2✔
49
}
50

51
type Transport struct {
52
        Base  http.RoundTripper
53
        where string
54
}
55

56
const boundary = "\n====================\n"
57

58
var TimeNow = func() time.Time { return time.Now().Truncate(time.Millisecond).UTC() }
2✔
59

60
func (d Transport) RoundTrip(req *http.Request) (*http.Response, error) {
2✔
61
        // NOTE(marius): return early if this is not a request with a body
2✔
62
        if req == nil {
2✔
63
                return d.Base.RoundTrip(req)
×
64
        }
×
65

66
        fullPath := filepath.Join(d.where, req.URL.Host+strings.ReplaceAll(req.URL.Path, "/", "-")+"-"+TimeNow().Format(time.RFC3339)+".req")
2✔
67
        ff, err := os.OpenFile(fullPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
2✔
68
        if err != nil {
2✔
69
                return d.Base.RoundTrip(req)
×
70
        }
×
71
        defer func() {
4✔
72
                _ = ff.Close()
2✔
73
        }()
2✔
74

75
        raw, _ := httputil.DumpRequestOut(req, req.Body != nil)
2✔
76
        if raw != nil {
4✔
77
                _, _ = ff.Write(raw)
2✔
78
        }
2✔
79

80
        res, err := d.Base.RoundTrip(req)
2✔
81
        if err != nil {
2✔
82
                return nil, err
×
83
        }
×
84

85
        if raw, _ = httputil.DumpResponse(res, res.Body != nil); raw != nil {
4✔
86
                _, _ = ff.WriteString(boundary)
2✔
87
                _, _ = ff.Write(raw)
2✔
88
        }
2✔
89

90
        return res, nil
2✔
91
}
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