diff --git a/eskipfile/remote.go b/eskipfile/remote.go index 2856600cef..79dc5af4f3 100644 --- a/eskipfile/remote.go +++ b/eskipfile/remote.go @@ -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, @@ -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 { diff --git a/net/httpclient.go b/net/httpclient.go index 89f485b491..a4c66edbf8 100644 --- a/net/httpclient.go +++ b/net/httpclient.go @@ -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 @@ -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 @@ -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{}, @@ -286,6 +296,7 @@ func NewTransport(options Options) *Transport { tracer: options.Tracer, beforeSend: options.BeforeSend, afterResponse: options.AfterResponse, + roundTripper: roundTripper, } if t.tracer != nil { @@ -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) }