GNOME Bugzilla – Bug 598505
Support g_file_input_stream_query_info() for HTTP input streams
Last modified: 2009-10-16 10:42:25 UTC
Created attachment 145470 [details] [review] Adds support for g_file_input_stream_query_info() to HTTP backend Currently you can only get HTTP header information from gio using HTTP HEAD requests. This requires a separate round trip to the server instead of accessing them using the HTTP GET request. See bug 596615 in Rhythmbox where HTTP redirects through buggy servers mean you cannot get the MIME type of a HTTP request. Patch attached which provides this support.
Example program illustrating the new feature: #include <glib.h> #include <gio/gio.h> int main(int argc, char **argv) { GFile *file; GFileInfo *fileinfo; GFileInputStream *input; const gchar *content_type; g_type_init(); // This URL gets redirected a number of times and one of the servers does not handle HEAD requests properly file = g_file_new_for_uri("http://www.pheedo.com/e/b7f9489601ab23c2b3e3516d44e5ac9b/podcast.mp3?e_id=EF83BDDD-E77B-CCA5-72F76C3AD1DE71CD&ref=p_itune"); input = g_file_read(file, NULL, NULL); fileinfo = g_file_input_stream_query_info(input, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_QUERY_INFO_NONE, NULL); content_type = g_file_info_get_content_type (fileinfo); g_message("content_type='%s'", content_type); return 0; }
It would be cleaner to add soup_input_stream_get_message() instead, and then have a single method used by both query_info() and query_info_on_read() to get data from that message and fill in the file info from it, rather than duplicating the same code in two places. Also, that new shared function should use soup_message_headers_get_content_length() and soup_message_headers_get_content_type() rather than parsing them itself, so it can correctly handle servers that send badly-formatted headers, etc.
Created attachment 145475 [details] [review] Adds support for g_file_input_stream_query_info() to HTTP backend Updated to share code with existing query_info method
Created attachment 145476 [details] [review] Adds support for g_file_input_stream_query_info() to HTTP backend Updated to use soup header methods for content type and length
I committed a modified (and split up) version of this patch to git. Thanks.