Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose http.Client to make the library work on GAE #53

Merged
merged 1 commit into from Dec 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions mackerel.go
Expand Up @@ -24,6 +24,7 @@ type Client struct {
Verbose bool
UserAgent string
AdditionalHeaders http.Header
HTTPClient *http.Client
}

func init() {
Expand All @@ -33,7 +34,7 @@ func init() {
// NewClient returns new mackerel.Client
func NewClient(apikey string) *Client {
u, _ := url.Parse(defaultBaseURL)
return &Client{u, apikey, false, defaultUserAgent, http.Header{}}
return &Client{u, apikey, false, defaultUserAgent, http.Header{}, &http.Client{}}
}

// NewClientWithOptions returns new mackerel.Client
Expand All @@ -42,7 +43,7 @@ func NewClientWithOptions(apikey string, rawurl string, verbose bool) (*Client,
if err != nil {
return nil, err
}
return &Client{u, apikey, verbose, defaultUserAgent, http.Header{}}, nil
return &Client{u, apikey, verbose, defaultUserAgent, http.Header{}, &http.Client{}}, nil
}

func (c *Client) urlFor(path string) *url.URL {
Expand Down Expand Up @@ -78,7 +79,7 @@ func (c *Client) Request(req *http.Request) (resp *http.Response, err error) {
}
}

client := &http.Client{} // same as http.DefaultClient
client := c.HTTPClient
client.Timeout = apiRequestTimeout
resp, err = client.Do(req)
if err != nil {
Expand Down