@@ -47,16 +47,11 @@ type GithubReleaseSource struct {
4747 IncludePrerelease bool `yaml:"include_prerelease"`
4848
4949 // Compiled configuration.
50- url * url.URL `yaml:"-"`
51- client * github.Client `yaml:"-"`
52- // httpClient is an unauthenticated default http.Client that is used for downloading release assets.
53- // We use a separate client instead of the same http.Client that we create and pass to
54- // the github.Client because that http.Client, when obtained using oauth2.NewClient(),
55- // does not return all headers in the request response.
56- httpClient * http.Client `yaml:"-"`
57- owner string `yaml:"-"` // repository owner
58- repo string `yaml:"-"`
59- tagNameRx * regexp.Regexp `yaml:"-"`
50+ url * url.URL `yaml:"-"`
51+ client * github.Client `yaml:"-"`
52+ owner string `yaml:"-"` // repository owner
53+ repo string `yaml:"-"`
54+ tagNameRx * regexp.Regexp `yaml:"-"`
6055 // notOlderThan is used to limit release listing to prevent excess API requests.
6156 notOlderThan * time.Time `yaml:"-"`
6257}
@@ -110,16 +105,10 @@ func (s *GithubReleaseSource) Validate(name string) []error {
110105
111106// Connect implements the Source interface.
112107func (s * GithubReleaseSource ) Connect (name string ) error {
113- // HTTP client for downloading release assets.
114- // Note: we don't need an authenticated client here, we'll just pass the token in the
115- // `Authorization` header when we download the asset.
116- s .httpClient = & http.Client {}
117-
118- // Use a separate http.Client for creating github.Client.
119- client2 := & http.Client {}
108+ c := http .DefaultClient
120109 if s .Token != "" {
121110 src := oauth2 .StaticTokenSource (& oauth2.Token {AccessToken : string (s .Token )})
122- client2 = oauth2 .NewClient (context .Background (), src )
111+ c = oauth2 .NewClient (context .Background (), src )
123112 }
124113 if s .url .Hostname () != "github.com" {
125114 // baseURL is s.url without the Path (/<owner>/<repo>).
@@ -128,14 +117,13 @@ func (s *GithubReleaseSource) Connect(name string) error {
128117 baseURL .RawPath = ""
129118 baseURLStr := baseURL .String ()
130119 var err error
131- s .client , err = github .NewEnterpriseClient (baseURLStr , baseURLStr , client2 )
120+ s .client , err = github .NewEnterpriseClient (baseURLStr , baseURLStr , c )
132121 if err != nil {
133122 return err
134123 }
135124 } else {
136- s .client = github .NewClient (client2 )
125+ s .client = github .NewClient (c )
137126 }
138-
139127 return nil
140128}
141129
@@ -215,7 +203,12 @@ func (s *GithubReleaseSource) GetFile(path string, requestHeaders schwift.Object
215203 if s .Token != "" {
216204 req .Header .Set ("Authorization" , fmt .Sprintf ("token %s" , s .Token ))
217205 }
218- resp , err := s .httpClient .Do (req )
206+
207+ // We use http.DefaultClient explicitly instead of retrieving (s.client.Client()) the
208+ // same http.Client that was passed to github.Client because that http.Client, when
209+ // obtained using oauth2.NewClient(), does not return all headers in the request
210+ // response.
211+ resp , err := http .DefaultClient .Do (req )
219212 if err != nil {
220213 return nil , FileState {}, fmt .Errorf ("skipping %s: GET failed: %s" , req .URL .String (), err .Error ())
221214 }
0 commit comments