diff --git a/util/http.go b/util/http.go index f1d30af77..8f987d3a2 100644 --- a/util/http.go +++ b/util/http.go @@ -6,6 +6,7 @@ import ( "fmt" "io/ioutil" "net/http" + "time" ) type HTTPHelper struct { @@ -17,7 +18,7 @@ type HTTPHelper struct { func NewHTTPHelper(log *Logger) *HTTPHelper { r := &HTTPHelper{ Log: log, - Client: &http.Client{}, + Client: &http.Client{Timeout: 10 * time.Second}, } return r } diff --git a/vehicle/bmw.go b/vehicle/bmw.go index 858e1c929..52dccb398 100644 --- a/vehicle/bmw.go +++ b/vehicle/bmw.go @@ -77,6 +77,7 @@ func (v *BMW) login(user, password string) error { req.Header.Set("Content-Type", "application/x-www-form-urlencoded") client := &http.Client{ + Timeout: v.HTTPHelper.Client.Timeout, CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }, // don't follow redirects } diff --git a/vehicle/porsche.go b/vehicle/porsche.go index 8e35e66b7..83411b3c5 100644 --- a/vehicle/porsche.go +++ b/vehicle/porsche.go @@ -5,7 +5,6 @@ import ( "errors" "fmt" "io/ioutil" - "log" "net/http" "net/http/cookiejar" "net/url" @@ -87,14 +86,15 @@ func NewPorscheFromConfig(log *util.Logger, other map[string]interface{}) api.Ve func (v *Porsche) login(user, password string) error { jar, err := cookiejar.New(&cookiejar.Options{PublicSuffixList: publicsuffix.List}) if err != nil { - log.Fatal(err) + return err } // the flow is using Oauth2 and >10 redirects client := &http.Client{ - Jar: jar, + Jar: jar, + Timeout: v.HTTPHelper.Client.Timeout, CheckRedirect: func(req *http.Request, via []*http.Request) error { - return nil + return nil // allow >10 redirects }, }