GNOME Bugzilla – Bug 551298
read edit/display name from Content-Disposition response header
Last modified: 2011-05-08 13:54:31 UTC
Sometimes, the content-disposition header is the only way you can get a useful filename out of a response. For example (from bug 551292): $ gvfs-info http://www.publicbroadcasting.net/tavis/.jukebox/media/tavis/751757/mp3/June2008Podcasts/podcast/480/751757.mp3 [some delay here caused by bug 551990] display name: QuerySplicedItemContent edit name: QuerySplicedItemContent ... Following the redirect chain manually (with curl -I or similar), you can see a Content-Disposition header in the final response: Content-Disposition: inline; filename="751757.mp3" It'd be great if we could get the edit/display names from this header, rather than hacking around the problem by using the filename from the original request.
Created attachment 118295 [details] [review] parse content-disposition header This was mostly a cut and pasted from gnome-vfs.
libsoup 2.25 has explicit Content-Disposition support, which parses much more reliably than that code (differences in optional whitespace, unescaping backslashed stuff in quoted-strings, etc), and also handles UTF-8-encoded filenames. Just do: GHashTable *params; if (soup_message_headers_get_content_disposition (msg->response_headers, NULL, ¶ms)) { const char *name = g_hash_table_lookup (params, "filename"); if (name) { g_free (basename); basename = g_strdup (name); } g_hash_table_destroy (params); } (Hm... probably ought to add an API to just get the filename directly...) And it strips the path off "filename" internally, so you don't have to do that yourself.
Created attachment 155925 [details] [review] Use soup's content_disposition support to set the basename Use the built-in support in soup to set the basename using the content-disposition header, if present.
Getting this patch applied would be awesome since AFAICT PyGTK applications can't work around it - there's no way to access the SoupMessage from PyGTK so we can't manually check for a Content-Disposition header.
I committed a slightly modified version to git master (fb8deae). Thank you both for the patches.