diff --git a/internal/maps/places/location.go b/internal/maps/places/location.go index d8aef7aba..ffe048217 100644 --- a/internal/maps/places/location.go +++ b/internal/maps/places/location.go @@ -5,6 +5,7 @@ import ( "fmt" "net/http" "strings" + "time" gc "github.com/patrickmn/go-cache" "github.com/photoprism/photoprism/pkg/s2" @@ -23,6 +24,7 @@ type Location struct { } var ReverseLookupURL = "https://places.photoprism.org/v1/location/%s" +var client = &http.Client{Timeout: 30 * time.Second} // TODO: Change timeout if needed func NewLocation(id string, lat float64, lng float64, name string, category string, place Place, cached bool) *Location { result := &Location{ @@ -59,13 +61,24 @@ func FindLocation(id string) (result Location, err error) { log.Debugf("places: query %s", url) - r, err := http.Get(url) + req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { log.Errorf("places: %s", err.Error()) return result, err } + r, err := client.Do(req) + + if err != nil { + log.Errorf("places: %s", err.Error()) + return result, err + } else if r.StatusCode >= 400 { + err = fmt.Errorf("places: request failed with status code %d", r.StatusCode) + log.Error(err) + return result, err + } + err = json.NewDecoder(r.Body).Decode(&result) if err != nil { diff --git a/internal/remote/remote.go b/internal/remote/remote.go index 6e9aa2b34..3f348cfa0 100644 --- a/internal/remote/remote.go +++ b/internal/remote/remote.go @@ -12,9 +12,10 @@ package remote import ( "net/http" + "time" ) -var client = &http.Client{} +var client = &http.Client{Timeout: 30 * time.Second} // TODO: Change timeout if needed const ( ServiceWebDAV = "webdav" diff --git a/internal/remote/webdav/webdav.go b/internal/remote/webdav/webdav.go index de40f69de..4c4161f74 100644 --- a/internal/remote/webdav/webdav.go +++ b/internal/remote/webdav/webdav.go @@ -12,6 +12,7 @@ import ( "io/ioutil" "os" "path" + "time" "github.com/photoprism/photoprism/internal/event" "github.com/photoprism/photoprism/pkg/fs" @@ -28,6 +29,8 @@ type Client struct { func New(url, user, pass string) Client { clt := gowebdav.NewClient(url, user, pass) + clt.SetTimeout(10 * time.Minute) // TODO: Change timeout if needed + result := Client{client: clt} return result