all: sync with master

This commit is contained in:
Eugene Burkov
2024-12-05 16:00:18 +03:00
parent 54f3a5f990
commit 3f95db98d3
143 changed files with 3476 additions and 2959 deletions

View File

@@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"io"
"maps"
"net/http"
"slices"
"time"
@@ -12,7 +13,7 @@ import (
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/ioutil"
"github.com/AdguardTeam/golibs/log"
"golang.org/x/exp/maps"
"github.com/c2h5oh/datasize"
)
// TODO(a.garipov): Make configurable.
@@ -28,8 +29,9 @@ type VersionInfo struct {
CanAutoUpdate aghalg.NullBool `json:"can_autoupdate,omitempty"`
}
// MaxResponseSize is responses on server's requests maximum length in bytes.
const MaxResponseSize = 64 * 1024
// maxVersionRespSize is the maximum length in bytes for version information
// response.
const maxVersionRespSize datasize.ByteSize = 64 * datasize.KB
// VersionInfo downloads the latest version information. If forceRecheck is
// false and there are cached results, those results are returned.
@@ -51,7 +53,7 @@ func (u *Updater) VersionInfo(forceRecheck bool) (vi VersionInfo, err error) {
}
defer func() { err = errors.WithDeferred(err, resp.Body.Close()) }()
r := ioutil.LimitReader(resp.Body, MaxResponseSize)
r := ioutil.LimitReader(resp.Body, maxVersionRespSize.Bytes())
// This use of ReadAll is safe, because we just limited the appropriate
// ReadCloser.
@@ -120,8 +122,8 @@ func (u *Updater) downloadURL(versionObj map[string]string) (dlURL, key string,
return dlURL, key, true
}
keys := maps.Keys(versionObj)
slices.Sort(keys)
keys := slices.Sorted(maps.Keys(versionObj))
log.Error("updater: key %q not found; got keys %q", key, keys)
return "", key, false