diff --git a/githubapp/client_creator.go b/githubapp/client_creator.go index 8b5a78d4e..049cb3da8 100644 --- a/githubapp/client_creator.go +++ b/githubapp/client_creator.go @@ -135,6 +135,7 @@ type clientCreator struct { cacheFunc func() httpcache.Cache alwaysValidate bool timeout time.Duration + transport http.RoundTripper } var _ ClientCreator = &clientCreator{} @@ -178,6 +179,15 @@ func WithClientMiddleware(middleware ...ClientMiddleware) ClientOption { } } +// WithTransport sets the http.RoundTripper used to make requests. Clients can +// provide an http.Transport instance to modify TLS, proxy, or timeout options. +// By default, clients use http.DefaultTransport. +func WithTransport(transport http.RoundTripper) ClientOption { + return func(c *clientCreator) { + c.transport = transport + } +} + func (c *clientCreator) NewAppClient() (*github.Client, error) { base := c.newHTTPClient() installation, transportError := newAppInstallation(c.integrationID, c.privKeyBytes, c.v3BaseURL) @@ -282,7 +292,7 @@ func (c *clientCreator) NewTokenSourceV4Client(ts oauth2.TokenSource) (*githubv4 func (c *clientCreator) newHTTPClient() *http.Client { return &http.Client{ - Transport: http.DefaultTransport, + Transport: c.transport, Timeout: c.timeout, } }