|
6 | 6 | "compress/zlib"
|
7 | 7 | "crypto/rand"
|
8 | 8 | "crypto/tls"
|
| 9 | + "crypto/x509" |
9 | 10 | "encoding/base64"
|
10 | 11 | "encoding/hex"
|
11 | 12 | "encoding/json"
|
@@ -336,25 +337,9 @@ func (c *context) interfaces() []Interface {
|
336 | 337 | // Packets will be dropped if the buffer is full. Used by NewClient.
|
337 | 338 | var MaxQueueBuffer = 100
|
338 | 339 |
|
339 |
| -func newTransport() Transport { |
340 |
| - t := &HTTPTransport{} |
341 |
| - rootCAs, err := gocertifi.CACerts() |
342 |
| - if err != nil { |
343 |
| - log.Println("raven: failed to load root TLS certificates:", err) |
344 |
| - } else { |
345 |
| - t.Client = &http.Client{ |
346 |
| - Transport: &http.Transport{ |
347 |
| - Proxy: http.ProxyFromEnvironment, |
348 |
| - TLSClientConfig: &tls.Config{RootCAs: rootCAs}, |
349 |
| - }, |
350 |
| - } |
351 |
| - } |
352 |
| - return t |
353 |
| -} |
354 |
| - |
355 | 340 | func newClient(tags map[string]string) *Client {
|
356 | 341 | client := &Client{
|
357 |
| - Transport: newTransport(), |
| 342 | + Transport: NewHTTPTransport(nil), |
358 | 343 | Tags: tags,
|
359 | 344 | context: &context{},
|
360 | 345 | sampleRate: 1.0,
|
@@ -528,6 +513,16 @@ func (client *Client) SetSampleRate(rate float32) error {
|
528 | 513 | return nil
|
529 | 514 | }
|
530 | 515 |
|
| 516 | +// SetTransport sets the client's Transport |
| 517 | +func (client *Client) SetTransport(t Transport) { |
| 518 | + client.mu.Lock() |
| 519 | + defer client.mu.Unlock() |
| 520 | + client.Transport = t |
| 521 | +} |
| 522 | + |
| 523 | +// SetTransport sets the Transport on the default *Client |
| 524 | +func SetTransport(t Transport) { DefaultClient.SetTransport(t) } |
| 525 | + |
531 | 526 | // SetRelease sets the "release" tag on the default *Client
|
532 | 527 | func SetRelease(release string) { DefaultClient.SetRelease(release) }
|
533 | 528 |
|
@@ -922,6 +917,34 @@ type HTTPTransport struct {
|
922 | 917 | *http.Client
|
923 | 918 | }
|
924 | 919 |
|
| 920 | +// HTTPTransportOptions are options to configure the HTTPTransport |
| 921 | +type HTTPTransportOptions struct { |
| 922 | + InsecureSkipVerify bool |
| 923 | + RootCAs *x509.CertPool |
| 924 | +} |
| 925 | + |
| 926 | +func NewHTTPTransport(o *HTTPTransportOptions) *HTTPTransport { |
| 927 | + if o == nil { |
| 928 | + o = &HTTPTransportOptions{} |
| 929 | + } |
| 930 | + if o.RootCAs == nil { |
| 931 | + // This can't actually error, so there's no point. |
| 932 | + rootCAs, _ := gocertifi.CACerts() |
| 933 | + o.RootCAs = rootCAs |
| 934 | + } |
| 935 | + return &HTTPTransport{ |
| 936 | + Client: &http.Client{ |
| 937 | + Transport: &http.Transport{ |
| 938 | + Proxy: http.ProxyFromEnvironment, |
| 939 | + TLSClientConfig: &tls.Config{ |
| 940 | + RootCAs: o.RootCAs, |
| 941 | + InsecureSkipVerify: o.InsecureSkipVerify, |
| 942 | + }, |
| 943 | + }, |
| 944 | + }, |
| 945 | + } |
| 946 | +} |
| 947 | + |
925 | 948 | func (t *HTTPTransport) Send(url, authHeader string, packet *Packet) error {
|
926 | 949 | if url == "" {
|
927 | 950 | return nil
|
|
0 commit comments