Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions config/http_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
"reflect"
"strings"
"time"

Expand Down Expand Up @@ -146,6 +147,8 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string) (http.RoundTri
),
}

rt = NewTLSConfigRoundTripper(cfg, tlsConfig, name, rt)

// If a bearer token is provided, create a round tripper that will set the
// Authorization header correctly on each request.
if len(cfg.BearerToken) > 0 {
Expand All @@ -162,6 +165,33 @@ func NewRoundTripperFromConfig(cfg HTTPClientConfig, name string) (http.RoundTri
return rt, nil
}

type tlsConfigRoundTripper struct {
cfg HTTPClientConfig
tlsConfig *tls.Config
name string
rt http.RoundTripper
}

// NewTLSConfigRoundTripper reads the tls configuration upton each request
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upon

// and updates the TLS configuration as needed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fullstop

func NewTLSConfigRoundTripper(cfg HTTPClientConfig, tlsConfig *tls.Config, name string, rt http.RoundTripper) http.RoundTripper {
return &tlsConfigRoundTripper{cfg, tlsConfig, name, rt}
}

func (rt *tlsConfigRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
tlsConfig, err := NewTLSConfig(&rt.cfg.TLSConfig)
if err != nil {
return nil, err
}
if !reflect.DeepEqual(tlsConfig, rt.tlsConfig) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there's mutable state in a tls.Config, so this may always return true and cause spurious reconnects

rt.rt, err = NewRoundTripperFromConfig(rt.cfg, rt.name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like a layering violation, it'd be cleaner to take in a function that'd create a new round tripper

if err != nil {
return nil, err
}
}
return rt.rt.RoundTrip(req)
}

type bearerAuthRoundTripper struct {
bearerToken Secret
rt http.RoundTripper
Expand Down