Changes the requestXml method to not use the default 30 second get timeout, uses 3 seconds instead.

This commit is contained in:
Duarte Avelar 2015-06-02 11:20:27 -04:00
parent c57ae84388
commit 7c18e85798

View File

@ -19,7 +19,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"time"
"golang.org/x/net/html/charset" "golang.org/x/net/html/charset"
"github.com/huin/goupnp/httpu" "github.com/huin/goupnp/httpu"
@ -64,7 +64,6 @@ func DiscoverDevices(searchTarget string) ([]MaybeRootDevice, error) {
maybe := &results[i] maybe := &results[i]
loc, err := response.Location() loc, err := response.Location()
if err != nil { if err != nil {
maybe.Err = ContextError{"unexpected bad location from search", err} maybe.Err = ContextError{"unexpected bad location from search", err}
continue continue
} }
@ -93,7 +92,11 @@ func DiscoverDevices(searchTarget string) ([]MaybeRootDevice, error) {
} }
func requestXml(url string, defaultSpace string, doc interface{}) error { func requestXml(url string, defaultSpace string, doc interface{}) error {
resp, err := http.Get(url) timeout := time.Duration(3 * time.Second)
client := http.Client{
Timeout: timeout,
}
resp, err := client.Get(url)
if err != nil { if err != nil {
return err return err
} }