[gvfs] http: use Content-Disposition filename if available



commit fb8deae57304a921a736c4ad932928bee614a16e
Author: Christian Kellner <gicmo gnome org>
Date:   Sun May 8 15:53:26 2011 +0200

    http: use Content-Disposition filename if available
    
    Set edit/displayname based on the filename in the Content-Disposition
    header if available.
    Based on a patch from Mike Gratton <mike vee net>.
    Fixes bug 551298

 daemon/gvfsbackendhttp.c |   32 ++++++++++++++++++++++++++------
 1 files changed, 26 insertions(+), 6 deletions(-)
---
diff --git a/daemon/gvfsbackendhttp.c b/daemon/gvfsbackendhttp.c
index fd01ad8..d983b59 100644
--- a/daemon/gvfsbackendhttp.c
+++ b/daemon/gvfsbackendhttp.c
@@ -558,13 +558,33 @@ file_info_from_message (SoupMessage *msg,
                         GFileInfo *info,
                         GFileAttributeMatcher *matcher)
 {
-  const SoupURI *uri;
-  const char    *text;
-  char          *basename;
-  char          *ed_name = NULL;
+  const char *text;
+  GHashTable *params;
+  char       *basename;
+  char       *ed_name;
 
-  uri = soup_message_get_uri (msg);
-  basename = http_uri_get_basename (uri->path);
+  basename = ed_name = NULL;
+
+  /* prefer the filename from the Content-Disposition (rfc2183) header
+     if one if present. See bug 551298. */
+  if (soup_message_headers_get_content_disposition (msg->response_headers,
+                                                    NULL, &params))
+    {
+      const char *name = g_hash_table_lookup (params, "filename");
+
+      if (name)
+        basename = g_strdup (name);
+
+      g_hash_table_destroy (params);
+    }
+
+  if (basename == NULL)
+    {
+      const SoupURI *uri;
+
+      uri = soup_message_get_uri (msg);
+      basename = http_uri_get_basename (uri->path);
+    }
 
   g_debug ("basename:%s\n", basename);
 



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