From 30c04f4ddb2a2b6e5eac1d9ea28217ee83235a36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 7 Jan 2022 14:37:04 +0100 Subject: [PATCH] Worker: set user agent string --- cmd/flamenco-worker-poc/main.go | 4 ++++ internal/appinfo/appinfo.go | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/cmd/flamenco-worker-poc/main.go b/cmd/flamenco-worker-poc/main.go index 853a8ae1..90f956f0 100644 --- a/cmd/flamenco-worker-poc/main.go +++ b/cmd/flamenco-worker-poc/main.go @@ -30,6 +30,10 @@ func main() { flamenco, err := api.NewClientWithResponses( "http://localhost:8080/", api.WithRequestEditorFn(basicAuthProvider.Intercept), + api.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error { + req.Header.Set("User-Agent", appinfo.UserAgent()) + return nil + }), ) if err != nil { log.Fatal().Err(err).Msg("error creating client") diff --git a/internal/appinfo/appinfo.go b/internal/appinfo/appinfo.go index 0138f297..a769c19e 100644 --- a/internal/appinfo/appinfo.go +++ b/internal/appinfo/appinfo.go @@ -12,3 +12,8 @@ var ApplicationVersion = "set-during-build" func FormattedApplicationInfo() string { return fmt.Sprintf("%s %s", ApplicationName, ApplicationVersion) } + +// UserAgent returns the application name & version suitable for the HTTP User-Agent header. +func UserAgent() string { + return fmt.Sprintf("%s/%s", ApplicationName, ApplicationVersion) +}