@@ -18,6 +18,17 @@ import (
1818 "github.com/octohelm/courier/pkg/statuserror"
1919)
2020
21+ type HttpTransport = func (rt http.RoundTripper ) http.RoundTripper
22+
23+ func WithHttpTransports (rts ... HttpTransport ) func (rt http.RoundTripper ) http.RoundTripper {
24+ return func (r http.RoundTripper ) http.RoundTripper {
25+ for _ , rt := range rts {
26+ r = rt (r )
27+ }
28+ return r
29+ }
30+ }
31+
2132type RoundTrip = func (request * http.Request ) (* http.Response , error )
2233
2334func HttpTransportFunc (round func (request * http.Request , next RoundTrip ) (* http.Response , error )) HttpTransport {
@@ -38,8 +49,6 @@ func (h *httpTransportFunc) RoundTrip(request *http.Request) (*http.Response, er
3849 return h .round (request , h .rt .RoundTrip )
3950}
4051
41- type HttpTransport = func (rt http.RoundTripper ) http.RoundTripper
42-
4352type Client struct {
4453 Endpoint string `flag:""`
4554 NewError func () error
@@ -62,6 +71,11 @@ func (c *Client) Do(ctx context.Context, req any, metas ...courier.Metadata) cou
6271 httpClient := HttpClientFromContext (ctx )
6372 if httpClient == nil {
6473 httpClient = GetReasonableClientContext (ctx , c .HttpTransports ... )
74+ } else {
75+ if httpClient .Transport == nil {
76+ httpClient .Transport = http .DefaultTransport
77+ }
78+ httpClient .Transport = WithHttpTransports (c .HttpTransports ... )(httpClient .Transport )
6579 }
6680
6781 resp , err := httpClient .Do (httpReq )
0 commit comments