After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 598505 - Support g_file_input_stream_query_info() for HTTP input streams
Support g_file_input_stream_query_info() for HTTP input streams
Status: RESOLVED FIXED
Product: gvfs
Classification: Core
Component: http backend
git master
Other All
: Normal normal
: ---
Assigned To: gvfs-maint
gvfs-maint
Depends on:
Blocks: 596615
 
 
Reported: 2009-10-15 01:07 UTC by Robert Ancell
Modified: 2009-10-16 10:42 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Adds support for g_file_input_stream_query_info() to HTTP backend (4.26 KB, patch)
2009-10-15 01:07 UTC, Robert Ancell
none Details | Review
Adds support for g_file_input_stream_query_info() to HTTP backend (5.08 KB, patch)
2009-10-15 02:29 UTC, Robert Ancell
none Details | Review
Adds support for g_file_input_stream_query_info() to HTTP backend (6.39 KB, patch)
2009-10-15 02:36 UTC, Robert Ancell
committed Details | Review

Description Robert Ancell 2009-10-15 01:07:24 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.
Comment 1 Robert Ancell 2009-10-15 01:12:35 UTC
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;
}
Comment 2 Dan Winship 2009-10-15 01:34:25 UTC
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.
Comment 3 Robert Ancell 2009-10-15 02:29:55 UTC
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
Comment 4 Robert Ancell 2009-10-15 02:36:07 UTC
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
Comment 5 Christian Kellner 2009-10-16 10:42:21 UTC
I committed a modified (and split up) version of this patch to git. Thanks.