Skip to content

Commit

Permalink
Merge pull request #164 from OSSystems/fix-timeout
Browse files Browse the repository at this point in the history
client: Fix net/http timeout
  • Loading branch information
otavio committed Nov 6, 2017
2 parents 20d6199 + ab35d30 commit 6f7b3e5
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package client

import (
"fmt"
"net"
"net/http"
"time"
)
Expand All @@ -21,7 +22,15 @@ const (
StateReportEndpoint = "/report"
)

const requestTimeout = 5 * time.Second
var defaultHttpTransport = http.Transport{
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial,
TLSHandshakeTimeout: 30 * time.Second,
ResponseHeaderTimeout: 30 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
}

type ApiClient struct {
http.Client
Expand All @@ -38,7 +47,7 @@ func (client *ApiClient) Request() *ApiRequest {
func NewApiClient(server string) *ApiClient {
return &ApiClient{
Client: http.Client{
Timeout: requestTimeout,
Transport: &defaultHttpTransport,
},
server: server,
}
Expand Down

0 comments on commit 6f7b3e5

Please sign in to comment.