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

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