[libgdata/wip/rishi/drive: 8/8] core: Get the content type from the response instead of hard coding it



commit eaf3fd8176e0e29ce1f638108dc31edb085a23f7
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Apr 16 18:51:57 2015 +0200

    core: Get the content type from the response instead of hard coding it
    
    There are places where we need to hard code the content type used by
    a specific service API. eg., when we want to upload and need to know
    whether to send JSON or XML. However, in this case, we have the
    response from the server and we can find the content type from that.
    We are already doing it in a few other places, so let's do it here too.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=684920

 gdata/gdata-service.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)
---
diff --git a/gdata/gdata-service.c b/gdata/gdata-service.c
index 300824b..d49fb24 100644
--- a/gdata/gdata-service.c
+++ b/gdata/gdata-service.c
@@ -1126,6 +1126,8 @@ gdata_service_query_single_entry (GDataService *self, GDataAuthorizationDomain *
        GDataEntry *entry;
        gchar *entry_uri;
        SoupMessage *message;
+       SoupMessageHeaders *headers;
+       const gchar *content_type;
 
        g_return_val_if_fail (GDATA_IS_SERVICE (self), NULL);
        g_return_val_if_fail (domain == NULL || GDATA_IS_AUTHORIZATION_DOMAIN (domain), NULL);
@@ -1150,7 +1152,10 @@ gdata_service_query_single_entry (GDataService *self, GDataAuthorizationDomain *
 
        g_assert (message->response_body->data != NULL);
 
-       if (g_strcmp0 (GDATA_PARSABLE_CLASS (klass)->get_content_type (), "application/json") == 0) {
+       headers = message->response_headers;
+       content_type = soup_message_headers_get_content_type (headers, NULL);
+
+       if (g_strcmp0 (content_type, "application/json") == 0) {
                entry = GDATA_ENTRY (gdata_parsable_new_from_json (entry_type, message->response_body->data, 
message->response_body->length, error));
        } else {
                entry = GDATA_ENTRY (gdata_parsable_new_from_xml (entry_type, message->response_body->data, 
message->response_body->length, error));


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