diff --git a/github/github.go b/github/github.go index ae0ee08c838..2f7653654ff 100644 --- a/github/github.go +++ b/github/github.go @@ -188,6 +188,14 @@ type service struct { client *Client } +// Client returns the http.Client used by this GitHub client. +func (c *Client) Client() *http.Client { + c.clientMu.Lock() + defer c.clientMu.Unlock() + clientCopy := *c.client + return &clientCopy +} + // ListOptions specifies the optional parameters to various List methods that // support offset pagination. type ListOptions struct { diff --git a/github/github_test.go b/github/github_test.go index 1eb0dba7337..d2240558da5 100644 --- a/github/github_test.go +++ b/github/github_test.go @@ -232,6 +232,14 @@ func TestNewClient(t *testing.T) { } } +func TestClient(t *testing.T) { + c := NewClient(nil) + c2 := c.Client() + if c.client == c2 { + t.Error("Client returned same http.Client, but should be different") + } +} + func TestNewEnterpriseClient(t *testing.T) { baseURL := "https://custom-url/api/v3/" uploadURL := "https://custom-upload-url/api/uploads/"