Blame SOURCES/0007-weather-add-app-ID-to-HTTP-user-agent.patch

7f8f23
From 9e04624edff61f381365485565477f5302a2b93e Mon Sep 17 00:00:00 2001
7f8f23
From: Michael Catanzaro <mcatanzaro@gnome.org>
7f8f23
Date: Fri, 19 Mar 2021 15:45:52 -0500
7f8f23
Subject: [PATCH 7/7] weather: add app ID to HTTP user agent
7f8f23
7f8f23
met.no has requested we add the app ID even if we cannot provide
7f8f23
application contact info. See #82.
7f8f23
---
7f8f23
 libgweather/gweather-weather.c | 34 ++++++++++++++++++++++++++++++++--
7f8f23
 1 file changed, 32 insertions(+), 2 deletions(-)
7f8f23
7f8f23
diff --git a/libgweather/gweather-weather.c b/libgweather/gweather-weather.c
7f8f23
index 62543169..f81aa7e2 100644
7f8f23
--- a/libgweather/gweather-weather.c
7f8f23
+++ b/libgweather/gweather-weather.c
7f8f23
@@ -583,6 +583,37 @@ dump_and_unref_cache (SoupCache *cache)
7f8f23
 
7f8f23
 static SoupSession *static_session;
7f8f23
 
7f8f23
+static const char *
7f8f23
+app_id (void)
7f8f23
+{
7f8f23
+    GApplication *app = g_application_get_default ();
7f8f23
+    const char *id;
7f8f23
+
7f8f23
+    if (app) {
7f8f23
+        id = g_application_get_application_id (app);
7f8f23
+        if (id)
7f8f23
+            return id;
7f8f23
+    }
7f8f23
+
7f8f23
+    return g_get_prgname ();
7f8f23
+}
7f8f23
+
7f8f23
+static char *
7f8f23
+compute_user_agent (void)
7f8f23
+{
7f8f23
+    return g_strdup_printf ("libgweather/%s (+https://gitlab.gnome.org/GNOME/libgweather/) (%s) ", LIBGWEATHER_VERSION, app_id ());
7f8f23
+}
7f8f23
+
7f8f23
+static const char *
7f8f23
+user_agent (void)
7f8f23
+{
7f8f23
+  static GOnce once = G_ONCE_INIT;
7f8f23
+
7f8f23
+  g_once (&once, compute_user_agent, NULL);
7f8f23
+
7f8f23
+  return once.retval;
7f8f23
+}
7f8f23
+
7f8f23
 static SoupSession *
7f8f23
 ref_session (void)
7f8f23
 {
7f8f23
@@ -595,8 +626,7 @@ ref_session (void)
7f8f23
 	return g_object_ref (session);
7f8f23
 
7f8f23
     session = soup_session_new ();
7f8f23
-    g_object_set (G_OBJECT (session), SOUP_SESSION_USER_AGENT,
7f8f23
-                  "libgweather/" LIBGWEATHER_VERSION " (+https://gitlab.gnome.org/GNOME/libgweather/) ", NULL);
7f8f23
+    g_object_set (G_OBJECT (session), SOUP_SESSION_USER_AGENT, user_agent (), NULL);
7f8f23
 
7f8f23
     cache = get_cache ();
7f8f23
     if (cache != NULL) {
7f8f23
-- 
7f8f23
2.30.2
7f8f23