mux-go icon indicating copy to clipboard operation
mux-go copied to clipboard

Allow custom http.Transport or http.Client

Open odannyc opened this issue 3 years ago • 3 comments

I'd like to add tracing to mux http calls but need a way to tap into the http.Client that mux uses under the hood. Typically other libraries expose a way to modify the http.Transport of the http.Client they're using.

I'm thinking maybe exposing this via the ConfigurationOption func:

func WithHTTPRoundTripper(roundTripper http.RoundTripper) ConfigurationOption {
	return func(c *Configuration) {
		c.httpRoundTripper = roundTripper
	}
}

and later on in client.go

if cfg.httpRoundTripper == nil {
    cfg.httpRoundTripper = http.DefaultTransport
}

c.httpc = &http.Client{
    Timeout: cfg.timeout,
    Transport: cfg.httpRoundTripper
}

odannyc avatar Nov 17 '21 17:11 odannyc

Hey @odannyc, thanks for the suggestion here, really appreciate it, I agree this would be useful.

I'll add this to the list of possible improvements for the golang SDK.

Thanks again for the feedback.

philcluff avatar Mar 04 '22 14:03 philcluff

Hey @philcluff, any update on this?

I have another use case for injecting custom transport into http client and now I need to fork repository to make it work.

rgalus avatar Feb 15 '24 18:02 rgalus

Hi @rgalus, Unfortunately this work is not currently planned, while we are working on an updated go SDK, this is not currently in scope.

Thank you.

philcluff avatar Feb 16 '24 10:02 philcluff