From a41e8a95bfcef252db34be534d3d3196e9c5a055 Mon Sep 17 00:00:00 2001 From: Daenney Date: Sat, 17 Feb 2024 09:54:10 +0100 Subject: [PATCH] [chore] Simplify the User-Agent string (#2645) * [chore] Simplify the User-Agent string RFC 9110[1] includes a definition for the format of a user-agent header: User-Agent = product *( RWS ( product / comment ) ) product = token ["/" product-version] product-version = token comment = "(" *( ctext / quoted-pair / comment ) ")" ctext = HTAB / SP / %x21-27 / %x2A-5B / %x5D-7E / obs-text An example given in the RFC: User-Agent: CERN-LineMode/2.15 libwww/2.17b3 The idea is typically start with the most important product/version, add a (comment) if necessary and then include any auxilliary products. However, the RFC warns against including too many auxiliary products as those can be unnecessarily revealing. For automated systems (i.e not a browser), the common and recommended format is (+uri-for-contact), followed with any additional / pairs that are relevant. This changes our UA to match that convention more closely. This makes it easier for administrators who do user-agent parsing for statistics or other purposes to correctly identify the version of GoToSocial. Currently tools tend to get confused by the lack of a / on the start of our string. [1]: https://www.rfc-editor.org/rfc/rfc9110.html#name-user-agents * [chore] Don't use app name in UA From all the GtS UAs I've collected, nobody seems to set/change this, so we might as well use the static string. The main usefulness for this is when you have multilpe GtS instances connecting to the same DB, so they can identify as different instances by changing the application name (though it should already be obvious from having different usernames). --- internal/transport/controller.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/internal/transport/controller.go b/internal/transport/controller.go index 9055b147f..32ef6d7c2 100644 --- a/internal/transport/controller.go +++ b/internal/transport/controller.go @@ -58,7 +58,6 @@ type controller struct { // NewController returns an implementation of the Controller interface for creating new transports func NewController(state *state.State, federatingDB federatingdb.DB, clock pub.Clock, client httpclient.SigningClient) Controller { var ( - applicationName = config.GetApplicationName() host = config.GetHost() proto = config.GetProtocol() version = config.GetSoftwareVersion() @@ -77,7 +76,7 @@ func NewController(state *state.State, federatingDB federatingdb.DB, clock pub.C clock: clock, client: client, trspCache: cache.NewTTL[string, *transport](0, 100, 0), - userAgent: fmt.Sprintf("%s (+%s://%s) gotosocial/%s", applicationName, proto, host, version), + userAgent: fmt.Sprintf("gotosocial/%s (+%s://%s)", version, proto, host), senders: senders, }