Skip to content

Commit

Permalink
Add WithTransport option to set TLS config (#102)
Browse files Browse the repository at this point in the history
Users can provide an http.Transport instance with non-default TLS,
proxy, or timeout settings.
  • Loading branch information
bluekeyes committed Aug 30, 2021
1 parent fa040a2 commit 08ca97a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion githubapp/client_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ type clientCreator struct {
cacheFunc func() httpcache.Cache
alwaysValidate bool
timeout time.Duration
transport http.RoundTripper
}

var _ ClientCreator = &clientCreator{}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
}
}
Expand Down

0 comments on commit 08ca97a

Please sign in to comment.