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

pace / bricks / 13717956986

06 Mar 2025 02:30PM UTC coverage: 51.823% (-4.8%) from 56.612%
13717956986

push

github

web-flow
Merge pull request #406 from pace/gomod-update

This updates all dependencies to the latest version, excluding

github.com/bsm/redislock
github.com/dave/jennifer

as newer versions lead to unwanted behavior.

54 of 82 new or added lines in 9 files covered. (65.85%)

453 existing lines in 15 files now uncovered.

4889 of 9434 relevant lines covered (51.82%)

20.93 hits per line

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

0.0
/maintenance/errors/raven/http.go
1
package raven
2

3
import (
4
        "errors"
5
        "fmt"
6
        "net"
7
        "net/http"
8
        "net/url"
9
        "runtime/debug"
10
        "strings"
11
)
12

UNCOV
13
func NewHttp(req *http.Request) *Http {
×
UNCOV
14
        proto := "http"
×
UNCOV
15
        if req.TLS != nil || req.Header.Get("X-Forwarded-Proto") == "https" {
×
16
                proto = "https"
×
17
        }
×
UNCOV
18
        h := &Http{
×
UNCOV
19
                Method:  req.Method,
×
UNCOV
20
                Cookies: req.Header.Get("Cookie"),
×
UNCOV
21
                Query:   sanitizeQuery(req.URL.Query()).Encode(),
×
UNCOV
22
                URL:     proto + "://" + req.Host + req.URL.Path,
×
UNCOV
23
                Headers: make(map[string]string, len(req.Header)),
×
UNCOV
24
        }
×
UNCOV
25
        if addr, port, err := net.SplitHostPort(req.RemoteAddr); err == nil {
×
UNCOV
26
                h.Env = map[string]string{"REMOTE_ADDR": addr, "REMOTE_PORT": port}
×
UNCOV
27
        }
×
UNCOV
28
        for k, v := range req.Header {
×
UNCOV
29
                h.Headers[k] = strings.Join(v, ",")
×
UNCOV
30
        }
×
UNCOV
31
        h.Headers["Host"] = req.Host
×
UNCOV
32
        return h
×
33
}
34

35
var querySecretFields = []string{"password", "passphrase", "passwd", "secret"}
36

UNCOV
37
func sanitizeQuery(query url.Values) url.Values {
×
UNCOV
38
        for _, keyword := range querySecretFields {
×
UNCOV
39
                for field := range query {
×
UNCOV
40
                        if strings.Contains(field, keyword) {
×
41
                                query[field] = []string{"********"}
×
42
                        }
×
43
                }
44
        }
UNCOV
45
        return query
×
46
}
47

48
// https://docs.getsentry.com/hosted/clientdev/interfaces/#context-interfaces
49
type Http struct {
50
        // Required
51
        URL    string `json:"url"`
52
        Method string `json:"method"`
53
        Query  string `json:"query_string,omitempty"`
54

55
        // Optional
56
        Cookies string            `json:"cookies,omitempty"`
57
        Headers map[string]string `json:"headers,omitempty"`
58
        Env     map[string]string `json:"env,omitempty"`
59

60
        // Must be either a string or map[string]string
61
        Data interface{} `json:"data,omitempty"`
62
}
63

64
func (h *Http) Class() string { return "request" }
×
65

66
// Recovery handler to wrap the stdlib net/http Mux.
67
// Example:
68
//
69
//        http.HandleFunc("/", raven.RecoveryHandler(func(w http.ResponseWriter, r *http.Request) {
70
//                ...
71
//        }))
72
func RecoveryHandler(handler func(http.ResponseWriter, *http.Request)) func(http.ResponseWriter, *http.Request) {
×
73
        return func(w http.ResponseWriter, r *http.Request) {
×
74
                defer func() {
×
75
                        if rval := recover(); rval != nil {
×
76
                                debug.PrintStack()
×
77
                                rvalStr := fmt.Sprint(rval)
×
78
                                var packet *Packet
×
79
                                if err, ok := rval.(error); ok {
×
80
                                        packet = NewPacket(rvalStr, NewException(errors.New(rvalStr), GetOrNewStacktrace(err, 2, 3, nil)), NewHttp(r))
×
81
                                } else {
×
82
                                        packet = NewPacket(rvalStr, NewException(errors.New(rvalStr), NewStacktrace(2, 3, nil)), NewHttp(r))
×
83
                                }
×
84
                                Capture(packet, nil)
×
85
                                w.WriteHeader(http.StatusInternalServerError)
×
86
                        }
87
                }()
88

89
                handler(w, r)
×
90
        }
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

© 2025 Coveralls, Inc