Add the default timeout for http request (#35)
This PR sets the default http timout to 60 seconds.
diff --git a/.travis.yml b/.travis.yml
index a6085a6..71fc279 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,6 +6,7 @@
include:
- os: linux
sudo: required
+ group: deprecated-2017Q3
go: 1.8
services: docker
diff --git a/whisk/client.go b/whisk/client.go
index 985bc75..c8cb311 100644
--- a/whisk/client.go
+++ b/whisk/client.go
@@ -31,6 +31,7 @@
"reflect"
"github.com/apache/incubator-openwhisk-client-go/wski18n"
"strings"
+ "time"
)
const (
@@ -46,6 +47,7 @@
DoNotProcessTimeOut = false
ExitWithErrorOnTimeout = true
ExitWithSuccessOnTimeout = false
+ DEFAULT_HTTP_TIMEOUT = 30
)
type Client struct {
@@ -91,6 +93,12 @@
config = config_input
}
+ if httpClient == nil {
+ httpClient = &http.Client{
+ Timeout: time.Second * DEFAULT_HTTP_TIMEOUT,
+ }
+ }
+
// Disable certificate checking in the dev environment if in insecure mode
if config.Insecure {
Debug(DbgInfo, "Disabling certificate checking.\n")
@@ -108,15 +116,11 @@
}
}
- http.DefaultClient.Transport = &http.Transport{
+ httpClient.Transport = &http.Transport{
TLSClientConfig: tlsConfig,
}
}
- if httpClient == nil {
- httpClient = http.DefaultClient
- }
-
var err error
var errStr = ""
if len(config.Host) == 0 {