File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed
Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -187,18 +187,24 @@ type installationTokenSource struct {
187187func NewInstallationTokenSource (id int64 , src oauth2.TokenSource , opts ... InstallationTokenSourceOpt ) oauth2.TokenSource {
188188 ctx := context .Background ()
189189
190+ httpClient := cleanHTTPClient ()
191+ httpClient .Transport = & oauth2.Transport {
192+ Source : oauth2 .ReuseTokenSource (nil , src ),
193+ Base : httpClient .Transport ,
194+ }
195+
190196 i := & installationTokenSource {
191197 id : id ,
192198 ctx : ctx ,
193199 src : src ,
194- client : github .NewClient (oauth2 . NewClient ( ctx , src ) ),
200+ client : github .NewClient (httpClient ),
195201 }
196202
197203 for _ , opt := range opts {
198204 opt (i )
199205 }
200206
201- return i
207+ return oauth2 . ReuseTokenSource ( nil , i )
202208}
203209
204210// Token generates a new GitHub App installation token for authenticating as a GitHub App installation.
Original file line number Diff line number Diff line change 1+ package githubauth
2+
3+ import (
4+ "net"
5+ "net/http"
6+ "runtime"
7+ "time"
8+ )
9+
10+ // cleanHTTPClient returns a new http.Client with clean defaults and connection pooling.
11+ // Implementation based on github.com/hashicorp/go-cleanhttp
12+ // Licensed under MPL-2.0: https://github.com/hashicorp/go-cleanhttp/blob/master/LICENSE
13+ func cleanHTTPClient () * http.Client {
14+ return & http.Client {
15+ Transport : & http.Transport {
16+ Proxy : http .ProxyFromEnvironment ,
17+ DialContext : (& net.Dialer {
18+ Timeout : 30 * time .Second ,
19+ KeepAlive : 30 * time .Second ,
20+ DualStack : true ,
21+ }).DialContext ,
22+ MaxIdleConns : 100 ,
23+ IdleConnTimeout : 90 * time .Second ,
24+ TLSHandshakeTimeout : 10 * time .Second ,
25+ ExpectContinueTimeout : 1 * time .Second ,
26+ ForceAttemptHTTP2 : true ,
27+ MaxIdleConnsPerHost : runtime .GOMAXPROCS (0 ) + 1 ,
28+ },
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments