Backend: Set http client timeouts

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-04-24 14:11:17 +02:00
parent 67eb71681f
commit 6af6129bf1
3 changed files with 19 additions and 2 deletions

View file

@ -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 {

View file

@ -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"

View file

@ -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