[libgweather/benzea/gnome-3-36-met.no-backport: 9/10] weather: add app ID to HTTP user agent




commit fff2e672d9ce3cb9ca5f7ee8c41fec1b4c3a2f1a
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Fri Mar 19 15:45:52 2021 -0500

    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.

 libgweather/gweather-weather.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
---
diff --git a/libgweather/gweather-weather.c b/libgweather/gweather-weather.c
index 17c3612f..a3489fe3 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) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]