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:
@@ -224,7 +224,7 @@ func filterForLatest(rels []upgrade.Release) []upgrade.Release {
|
||||
return filtered
|
||||
}
|
||||
|
||||
var userAgentOSArchExp = regexp.MustCompile(`^syncthing.*\(.+ (\w+)-(\w+)\)$`)
|
||||
var userAgentOSArchExp = regexp.MustCompile(`^[Ss]yncthing.*\(.+ (\w+)-(\w+)\)$`)
|
||||
|
||||
func filterForCompatibility(rels []upgrade.Release, ua, osv string) []upgrade.Release {
|
||||
osArch := userAgentOSArchExp.FindStringSubmatch(ua)
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
"github.com/syncthing/syncthing/lib/config"
|
||||
"github.com/syncthing/syncthing/lib/events"
|
||||
"github.com/syncthing/syncthing/lib/locations"
|
||||
@@ -115,6 +116,7 @@ func (c *apiClient) Endpoint() string {
|
||||
|
||||
func (c *apiClient) Do(req *http.Request) (*http.Response, error) {
|
||||
req.Header.Set("X-Api-Key", c.apikey)
|
||||
req.Header.Set("User-Agent", build.UserAgent())
|
||||
resp, err := c.Client.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/syncthing/syncthing/internal/slogutil"
|
||||
"github.com/syncthing/syncthing/lib/build"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -81,6 +82,7 @@ func uploadPanicLog(ctx context.Context, urlBase, file string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
headReq.Header.Set("User-Agent", build.UserAgent())
|
||||
|
||||
// Set a reasonable timeout on the HEAD request
|
||||
headCtx, headCancel := context.WithTimeout(ctx, headRequestTimeout)
|
||||
@@ -101,6 +103,7 @@ func uploadPanicLog(ctx context.Context, urlBase, file string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
putReq.Header.Set("User-Agent", build.UserAgent())
|
||||
|
||||
// Set a reasonable timeout on the PUT request
|
||||
putCtx, putCancel := context.WithTimeout(ctx, putRequestTimeout)
|
||||
|
||||
@@ -374,6 +374,7 @@ func upgradeViaRest() error {
|
||||
target := u.String()
|
||||
r, _ := http.NewRequest(http.MethodPost, target, nil)
|
||||
r.Header.Set("X-Api-Key", cfg.GUI().APIKey)
|
||||
r.Header.Set("User-Agent", build.UserAgent())
|
||||
|
||||
tr := &http.Transport{
|
||||
DialContext: dialer.DialContext,
|
||||
@@ -955,6 +956,7 @@ func (c browserCmd) Run() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
req.Header.Set("User-Agent", build.UserAgent())
|
||||
_, err = http.DefaultClient.Do(req) //nolint:bodyclose // we're exiting in a millisecond
|
||||
if err != nil {
|
||||
slog.Error("GUI not available", slogutil.Error(err))
|
||||
|
||||
Reference in New Issue
Block a user