chore: set User-Agent on all outgoing HTTP requests (#10867)
It's only polite, and it enables better troubleshooting in situations like weird-ass requests to the upgrades download service. --------- Signed-off-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
@@ -15,20 +15,19 @@ import (
|
||||
"compress/gzip"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/shirou/gopsutil/v4/host"
|
||||
"github.com/syncthing/syncthing/internal/slogutil"
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/dialer"
|
||||
"github.com/syncthing/syncthing/lib/signature"
|
||||
"github.com/syncthing/syncthing/lib/tlsutil"
|
||||
@@ -79,13 +78,13 @@ func init() {
|
||||
osVersion = strings.TrimSpace(osVersion)
|
||||
}
|
||||
|
||||
func upgradeClientGet(url, version string) (*http.Response, error) {
|
||||
func upgradeClientGet(url string) (*http.Response, error) {
|
||||
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header.Set("User-Agent", fmt.Sprintf(`syncthing %s (%s %s-%s)`, version, runtime.Version(), runtime.GOOS, runtime.GOARCH))
|
||||
req.Header.Set("User-Agent", build.UserAgent())
|
||||
if osVersion != "" {
|
||||
req.Header.Set("Syncthing-Os-Version", osVersion)
|
||||
}
|
||||
@@ -95,7 +94,7 @@ func upgradeClientGet(url, version string) (*http.Response, error) {
|
||||
// FetchLatestReleases returns the latest releases. The "current" parameter
|
||||
// is used for setting the User-Agent only.
|
||||
func FetchLatestReleases(releasesURL, current string) []Release {
|
||||
resp, err := upgradeClientGet(releasesURL, current)
|
||||
resp, err := upgradeClientGet(releasesURL)
|
||||
if err != nil {
|
||||
slog.Warn("Failed to fetch latest release information", slogutil.Error(err))
|
||||
return nil
|
||||
@@ -227,6 +226,7 @@ func readRelease(archiveName, dir, url string) (string, error) {
|
||||
}
|
||||
|
||||
req.Header.Add("Accept", "application/octet-stream")
|
||||
req.Header.Set("User-Agent", build.UserAgent())
|
||||
resp, err := upgradeClient.Do(req)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
||||
Reference in New Issue
Block a user