Skip to content

Commit e64235c

Browse files
Hash2049hang.jiang
authored andcommitted
support http proxy
Signed-off-by: hang.jiang <hang.jiang@daocloud.io>
1 parent 862134b commit e64235c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

github/github.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,11 @@ func NewClient(httpClient *http.Client) *Client {
348348
return c
349349
}
350350

351+
// NewClientWithEnvProxy enhances NewClient with the HttpProxy env.
352+
func NewClientWithEnvProxy() *Client {
353+
return NewClient(&http.Client{Transport: &http.Transport{Proxy: http.ProxyFromEnvironment}})
354+
}
355+
351356
// NewTokenClient returns a new GitHub API client authenticated with the provided token.
352357
func NewTokenClient(ctx context.Context, token string) *Client {
353358
return NewClient(oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})))

github/github_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,13 @@ func TestNewClient(t *testing.T) {
264264
}
265265
}
266266

267+
func TestNewClientWithEnvProxy(t *testing.T) {
268+
client := NewClientWithEnvProxy()
269+
if got, want := client.BaseURL.String(), defaultBaseURL; got != want {
270+
t.Errorf("NewClient BaseURL is %v, want %v", got, want)
271+
}
272+
}
273+
267274
func TestClient(t *testing.T) {
268275
c := NewClient(nil)
269276
c2 := c.Client()

0 commit comments

Comments
 (0)