[gupnp/gupnp-0.18: 1/12] Properly quote charset in SOAP requests



commit de2d1e3b97308a6c0941b271043bfab3b885299d
Author: Jens Georg <mail jensge org>
Date:   Fri Sep 9 09:23:49 2011 +0200

    Properly quote charset in SOAP requests
    
    soup_message_headers_append apparently eats the quotes. So we're using
    soup_message_headers_set_content_type instead.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=658633

 libgupnp/gupnp-service.c |   12 +++++++++---
 libgupnp/http-headers.c  |   14 ++++++++++----
 2 files changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/libgupnp/gupnp-service.c b/libgupnp/gupnp-service.c
index 7d44ed5..66b89ba 100644
--- a/libgupnp/gupnp-service.c
+++ b/libgupnp/gupnp-service.c
@@ -252,6 +252,10 @@ static void
 finalize_action (GUPnPServiceAction *action)
 {
         SoupServer *server;
+        GHashTable *params;
+
+        params = g_hash_table_new (g_str_hash, g_str_equal);
+        g_hash_table_insert (params, "charset", "utf-8");
 
         /* Embed action->response_str in a SOAP document */
         g_string_prepend (action->response_str,
@@ -272,9 +276,9 @@ finalize_action (GUPnPServiceAction *action)
                          "</s:Body>"
                          "</s:Envelope>");
 
-        soup_message_headers_replace (action->msg->response_headers,
-                                      "Content-Type",
-                                      "text/xml; charset=\"utf-8\"");
+        soup_message_headers_set_content_type (action->msg->response_headers,
+                                               "text/xml",
+                                               params);
 
         if (action->accept_gzip && action->response_str->len > 1024) {
                 http_response_set_body_gzip (action->msg,
@@ -304,6 +308,8 @@ finalize_action (GUPnPServiceAction *action)
 
         /* Cleanup */
         gupnp_service_action_unref (action);
+
+        g_hash_table_destroy (params);
 }
 
 /**
diff --git a/libgupnp/http-headers.c b/libgupnp/http-headers.c
index abff749..3705381 100644
--- a/libgupnp/http-headers.c
+++ b/libgupnp/http-headers.c
@@ -310,6 +310,7 @@ http_response_set_content_type (SoupMessage  *msg,
                                 gsize         data_size)
 {
         char *content_type, *mime;
+        GHashTable *params = NULL;
 
         content_type = g_content_type_guess
                                 (path,
@@ -321,12 +322,17 @@ http_response_set_content_type (SoupMessage  *msg,
                 mime = g_strdup ("application/octet-stream");
         else if (strcmp (mime, "application/xml") == 0) {
                 g_free (mime);
-                mime = g_strdup ("text/xml; charset=\"utf-8\"");
+                mime = g_strdup ("text/xml");
+                params = g_hash_table_new (g_str_hash, g_str_equal);
+                g_hash_table_insert (params, "charset", "utf-8");
         }
 
-        soup_message_headers_append (msg->response_headers,
-                                     "Content-Type",
-                                     mime);
+        soup_message_headers_set_content_type (msg->response_headers,
+                                               mime,
+                                               params);
+
+        if (params)
+                g_hash_table_destroy (params);
 
         g_free (mime);
         g_free (content_type);



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