Skip to content

Commit

Permalink
Use default 30s timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthur White committed Mar 28, 2018
1 parent 8d01005 commit 1d7d78a
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,28 @@ import (
"net/url"
"os"
"strings"
"time"
)

var httpNoRedirectClient = &http.Client{
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
},
var (
defaultTimeout = 30 * time.Second

client = &http.Client{
Timeout: defaultTimeout,
}

clientNoRedirect = &http.Client{
Timeout: defaultTimeout,
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
return http.ErrUseLastResponse
},
}
)

// Timeout sets the global client request timeout. Default is 30 seconds.
func Timeout(t time.Duration) {
client.Timeout = t
clientNoRedirect.Timeout = t
}

type body struct {
Expand Down Expand Up @@ -221,7 +237,7 @@ func (r *request) Do() (*Response, error) {

var res *http.Response
if r.noRedir {
res, err = httpNoRedirectClient.Do(req)
res, err = clientNoRedirect.Do(req)
} else {
res, err = http.DefaultClient.Do(req)
}
Expand Down

0 comments on commit 1d7d78a

Please sign in to comment.