Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In #245, support was proposed for overriding the
http.Client
. However, I only want to modify thehttp.Transport
, so I have to duplicate the entirehttp.Client
configuration code inside my module, like so:Then, I set the
cfg.Client.Transport
after calling this function.This is brittle, because
go-chef/chef
's implementation may change, and I'd like to get those changes too whenever the rest of the package is updated.I'd prefer a way to set the
Transport
on the constructed*http.Client
. However, I still need to be able to chain to the oldTransport
, for the same reason as above: I don't want to duplicate all the code to setProxy
Dial
TLSClientConfig
TLSHandshakeTimeout
, and risk it drifting away from this implementation.So I added the
Config
fieldRoundTripper func(http.RoundTripper) http.RoundTripper
which can modify or replace the existingTransport
.I wrote tests similar to the
Client
tests from #246. They don't actually test whether the override is used, only whether it is set.Alternate approaches
I don't know which approach is best, so I wrote a PR for you to help me decide. Please share your thoughts!
func
which modifieshttp.Client.Transport
. (This PR).func
which modifieshttp.Client
- a caller could replace, save a pointer, or mutate the client at will, without being so tightly coupled to theTransport
specifically.else { tlsConfig := .... c.client = &http.Client{ ... } }
code as a constructor function. The consumer can mutate/replace and pass it back ascfg.Client
.Client *http.Client
field on thetype Client struct
. (Why not? Every other field is exported!)