Skip to content

Commit

Permalink
Update http client (#2)
Browse files Browse the repository at this point in the history
irfannurhakim authored Apr 26, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent d3d26e2 commit 4e75e04
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
@@ -20,13 +20,13 @@ import (
"io/ioutil"
"log"
"math"
"net"
"net/http"
"net/url"
"os"
"strings"
"time"

"github.com/hashicorp/go-cleanhttp"
"github.com/rubyist/circuitbreaker"
)

@@ -39,7 +39,7 @@ var (
// Default circuit breaker configuration
defaultTimeout = 1 * time.Minute
defaultThreshold = int64(4)
defaultHTTPClient = cleanhttp.DefaultClient()
defaultHTTPClient = NewHTTPClient()

// defaultClient is used for performing requests without explicitly making
// a new client. It is purposely private to avoid modifications.
@@ -321,3 +321,19 @@ func PostForm(url string, data url.Values) (*http.Response, error) {
func (c *Client) PostForm(url string, data url.Values) (*http.Response, error) {
return c.Post(url, "application/x-www-form-urlencoded", strings.NewReader(data.Encode()))
}

// NewHTTPClient returns default http client
func NewHTTPClient() *http.Client {
defaultRoundTripper := http.DefaultTransport
defaultTransportPointer, _ := defaultRoundTripper.(*http.Transport)

defaultTransport := *defaultTransportPointer
defaultTransport.MaxIdleConns = 1024
defaultTransport.MaxIdleConnsPerHost = 1024
defaultTransport.Dial = (&net.Dialer{
Timeout: 60 * time.Second,
KeepAlive: 60 * 60 * time.Second,
}).Dial

return &http.Client{Transport: &defaultTransport}
}

0 comments on commit 4e75e04

Please sign in to comment.