fix(font): improve font download timeouts

This commit is contained in:
Iavael 2023-04-21 14:31:18 +03:00 committed by Jan De Dobbeleer
parent 41e90d66c8
commit 2452475d8c

View file

@ -8,6 +8,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"net"
"net/http" "net/http"
"net/url" "net/url"
"time" "time"
@ -37,10 +38,16 @@ func isZipFile(data []byte) bool {
} }
func getRemoteFile(location string) (data []byte, err error) { func getRemoteFile(location string) (data []byte, err error) {
client := &http.Client{} client := &http.Client{
ctx, cancelF := context.WithTimeout(context.Background(), time.Second*time.Duration(60)) Transport: &http.Transport{
defer cancelF() Dial: (&net.Dialer{
req, err := http.NewRequestWithContext(ctx, "GET", location, nil) Timeout: 10 * time.Second,
}).Dial,
TLSHandshakeTimeout: 10 * time.Second,
ResponseHeaderTimeout: 10 * time.Second,
},
}
req, err := http.NewRequestWithContext(context.Background(), "GET", location, nil)
if err != nil { if err != nil {
return nil, err return nil, err
} }