Просмотр исходного кода

Fix dowloading timeout configuration

DarthSim 7 лет назад
Родитель
Сommit
f9fbfefad6
2 измененных файлов с 8 добавлено и 3 удалено
  1. 1 0
      config.go
  2. 7 3
      download.go

+ 1 - 0
config.go

@@ -188,4 +188,5 @@ func init() {
 	}
 
 	initVips()
+	initDownloading()
 }

+ 7 - 3
download.go

@@ -18,9 +18,7 @@ import (
 	_ "golang.org/x/image/webp"
 )
 
-var downloadClient = http.Client{
-	Timeout: time.Duration(conf.DownloadTimeout) * time.Second,
-}
+var downloadClient *http.Client
 
 type netReader struct {
 	reader *bufio.Reader
@@ -57,6 +55,12 @@ func (r *netReader) GrowBuf(s int) {
 	r.buf.Grow(s)
 }
 
+func initDownloading() {
+	downloadClient = &http.Client{
+		Timeout: time.Duration(conf.DownloadTimeout) * time.Second,
+	}
+}
+
 func checkTypeAndDimensions(r io.Reader) (imageType, error) {
 	imgconf, imgtypeStr, err := image.DecodeConfig(r)
 	imgtype, imgtypeOk := imageTypes[imgtypeStr]