[gupnp/gupnp-1.0] Propagate User-Agent to message from cache



commit b18ed085c5993de34febe7f1797bc79a323a4318
Author: Jens Georg <mail jensge org>
Date:   Sun Apr 30 16:57:45 2017 +0200

    Propagate User-Agent to message from cache
    
    Instead of just populating the cache, also update the message if there isn't
    one in the message but we have a cached value.

 libgupnp/gupnp-context.c |   25 +++++++++++++++++++++----
 1 files changed, 21 insertions(+), 4 deletions(-)
---
diff --git a/libgupnp/gupnp-context.c b/libgupnp/gupnp-context.c
index 75bea6d..641c59a 100644
--- a/libgupnp/gupnp-context.c
+++ b/libgupnp/gupnp-context.c
@@ -929,7 +929,7 @@ host_path_handler (G_GNUC_UNUSED SoupServer        *server,
                    SoupMessage                     *msg,
                    const char                      *path,
                    G_GNUC_UNUSED GHashTable        *query,
-                   G_GNUC_UNUSED SoupClientContext *client,
+                   SoupClientContext               *client_ctx,
                    gpointer                         user_data)
 {
         char *local_path, *path_to_open;
@@ -940,6 +940,7 @@ host_path_handler (G_GNUC_UNUSED SoupServer        *server,
         GError *error;
         HostPathData *host_path_data;
         const char *user_agent;
+        const char *host;
 
         orig_locales = NULL;
         locales      = NULL;
@@ -967,9 +968,25 @@ host_path_handler (G_GNUC_UNUSED SoupServer        *server,
 
         user_agent = soup_message_headers_get_one (msg->request_headers,
                                                    "User-Agent");
-        update_client_cache (host_path_data->context,
-                             soup_client_context_get_host (client),
-                             user_agent);
+        host = soup_client_context_get_host (client_ctx);
+
+        /* If there was no User-Agent in the request, try to guess from the
+         * discovery message and put it into the response headers for further
+         * processing. Otherwise use the agent to populate the cache.
+         */
+        if (user_agent == NULL) {
+                GSSDPClient *client = GSSDP_CLIENT (host_path_data->context);
+
+                user_agent = gssdp_client_guess_user_agent (client, host);
+
+                if (user_agent != NULL) {
+                        soup_message_headers_append (msg->response_headers,
+                                                     "User-Agent",
+                                                     user_agent);
+                }
+        } else {
+                update_client_cache (host_path_data->context, host, user_agent);
+        }
 
         /* Construct base local path */
         local_path = construct_local_path (path, user_agent, host_path_data);


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