Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion eskipfile/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type RemoteWatchOptions struct {

// HTTPTimeout is the generic timeout for any phase of a single HTTP request to RemoteFile.
HTTPTimeout time.Duration

// CustomHttpRoundTripperWrap is a custom http.RoundTripper that can be used to wrap the default http.RoundTripper
CustomHttpRoundTripperWrap func(http.RoundTripper) http.RoundTripper
}

// RemoteWatch creates a route configuration client with (remote) file watching. Watch doesn't follow file system nodes,
Expand All @@ -67,7 +70,7 @@ func RemoteWatch(o *RemoteWatchOptions) (routing.DataClient, error) {
localPath: tempFilename.Name(),
threshold: o.Threshold,
verbose: o.Verbose,
http: net.NewClient(net.Options{Timeout: o.HTTPTimeout}),
http: net.NewClient(net.Options{Timeout: o.HTTPTimeout, CustomHttpRoundTripperWrap: o.CustomHttpRoundTripperWrap}),
}

if o.FailOnStartup {
Expand Down
13 changes: 12 additions & 1 deletion net/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ type Options struct {
BeforeSend func(*http.Request)
// AfterResponse is a hook function that runs just after executing RoundTrip(*http.Request)
AfterResponse func(*http.Response, error)

// CustomHttpRoundTripperWrap is a hook function that wraps the http.RoundTripper
CustomHttpRoundTripperWrap func(http.RoundTripper) http.RoundTripper
}

// Transport wraps an http.Transport and adds support for tracing and
Expand All @@ -224,6 +227,7 @@ type Transport struct {
bearerToken string
beforeSend func(*http.Request)
afterResponse func(*http.Response, error)
roundTripper http.RoundTripper
}

// NewTransport creates a wrapped http.Transport, with regular DNS
Expand Down Expand Up @@ -278,6 +282,12 @@ func NewTransport(options Options) *Transport {
ExpectContinueTimeout: options.ExpectContinueTimeout,
}
}
var roundTripper http.RoundTripper
if options.CustomHttpRoundTripperWrap != nil {
roundTripper = options.CustomHttpRoundTripperWrap(htransport)
} else {
roundTripper = htransport
}

t := &Transport{
once: sync.Once{},
Expand All @@ -286,6 +296,7 @@ func NewTransport(options Options) *Transport {
tracer: options.Tracer,
beforeSend: options.BeforeSend,
afterResponse: options.AfterResponse,
roundTripper: roundTripper,
}

if t.tracer != nil {
Expand Down Expand Up @@ -381,7 +392,7 @@ func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) {
if t.beforeSend != nil {
t.beforeSend(req)
}
rsp, err := t.tr.RoundTrip(req)
rsp, err := t.roundTripper.RoundTrip(req)
if t.afterResponse != nil {
t.afterResponse(rsp, err)
}
Expand Down