summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Catanzaro <mcatanzaro@gnome.org>2021-03-19 15:45:52 -0500
committerBenjamin Berg <bberg@redhat.com>2021-03-25 23:27:00 +0100
commit46ce7f9cc674c086404077492fd329a5389cc673 (patch)
treec1a47ad78ddf46fbec1168043c38a4a8c66a6996
parenta46b17ed4401e9365590a4562ca3658b84e4b5a0 (diff)
downloadlibgweather-46ce7f9cc674c086404077492fd329a5389cc673.tar.gz
weather: add app ID to HTTP user agent
met.no has requested we add the app ID even if we cannot provide application contact info. See #82.
-rw-r--r--libgweather/gweather-weather.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/libgweather/gweather-weather.c b/libgweather/gweather-weather.c
index 17c3612..a3489fe 100644
--- a/libgweather/gweather-weather.c
+++ b/libgweather/gweather-weather.c
@@ -634,6 +634,30 @@ dump_and_unref_cache (SoupCache *cache)
static SoupSession *static_session;
+static const char *
+app_id (void)
+{
+ GApplication *app = g_application_get_default ();
+ const char *id;
+
+ if (app) {
+ id = g_application_get_application_id (app);
+ if (id)
+ return id;
+ }
+
+ return g_get_prgname ();
+}
+
+static const char *
+user_agent (void)
+{
+ static char *ua = NULL;
+ if (ua == NULL)
+ ua = g_strdup_printf ("libgweather/%s (+https://gitlab.gnome.org/GNOME/libgweather/) (%s) ", LIBGWEATHER_VERSION, app_id ());
+ return ua;
+}
+
static SoupSession *
ref_session (void)
{
@@ -646,8 +670,7 @@ ref_session (void)
return g_object_ref (session);
session = soup_session_new ();
- g_object_set (G_OBJECT (session), SOUP_SESSION_USER_AGENT,
- "libgweather/" LIBGWEATHER_VERSION " (+https://gitlab.gnome.org/GNOME/libgweather/) ", NULL);
+ g_object_set (G_OBJECT (session), SOUP_SESSION_USER_AGENT, user_agent (), NULL);
cache = get_cache ();
if (cache != NULL) {