mirror of
https://github.com/rancher/os.git
synced 2025-09-04 00:04:25 +00:00
Add http timeout when loading resource
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/rancher/os/config"
|
"github.com/rancher/os/config"
|
||||||
"github.com/rancher/os/pkg/log"
|
"github.com/rancher/os/pkg/log"
|
||||||
@@ -15,6 +16,10 @@ import (
|
|||||||
composeConfig "github.com/docker/libcompose/config"
|
composeConfig "github.com/docker/libcompose/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultTimeout = 10 * time.Second
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
ErrNoNetwork = errors.New("Networking not available to load resource")
|
ErrNoNetwork = errors.New("Networking not available to load resource")
|
||||||
ErrNotFound = errors.New("Failed to find resource")
|
ErrNotFound = errors.New("Failed to find resource")
|
||||||
@@ -110,7 +115,10 @@ func LoadFromNetwork(location string) ([]byte, error) {
|
|||||||
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
log.Debugf("LoadFromNetwork(%s)", location)
|
log.Debugf("LoadFromNetwork(%s)", location)
|
||||||
resp, err = http.Get(location)
|
netClient := &http.Client{
|
||||||
|
Timeout: defaultTimeout,
|
||||||
|
}
|
||||||
|
resp, err = netClient.Get(location)
|
||||||
log.Debugf("LoadFromNetwork(%s) returned %v, %v", location, resp, err)
|
log.Debugf("LoadFromNetwork(%s) returned %v, %v", location, resp, err)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
Reference in New Issue
Block a user