[libsoup] SoupMessage: add :request-body-data and :response-body-data properties



commit d24e469c9a4e11a6ca05dab8b4c95d4d14186c75
Author: Dan Winship <danw gnome org>
Date:   Sun Aug 25 11:05:44 2013 -0400

    SoupMessage: add :request-body-data and :response-body-data properties
    
    Make it easier to use the request and response bodies from
    introspection by providing accessors to get them as GBytes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=704105

 libsoup/soup-message.c |   57 ++++++++++++++++++++++++++++++++++++++++++++++++
 libsoup/soup-message.h |   32 ++++++++++++++------------
 2 files changed, 74 insertions(+), 15 deletions(-)
---
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index b51f234..07967fc 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -131,8 +131,10 @@ enum {
        PROP_REASON_PHRASE,
        PROP_FIRST_PARTY,
        PROP_REQUEST_BODY,
+       PROP_REQUEST_BODY_DATA,
        PROP_REQUEST_HEADERS,
        PROP_RESPONSE_BODY,
+       PROP_RESPONSE_BODY_DATA,
        PROP_RESPONSE_HEADERS,
        PROP_TLS_CERTIFICATE,
        PROP_TLS_ERRORS,
@@ -254,6 +256,7 @@ soup_message_get_property (GObject *object, guint prop_id,
 {
        SoupMessage *msg = SOUP_MESSAGE (object);
        SoupMessagePrivate *priv = SOUP_MESSAGE_GET_PRIVATE (msg);
+       SoupBuffer *buf;
 
        switch (prop_id) {
        case PROP_METHOD:
@@ -283,12 +286,22 @@ soup_message_get_property (GObject *object, guint prop_id,
        case PROP_REQUEST_BODY:
                g_value_set_boxed (value, msg->request_body);
                break;
+       case PROP_REQUEST_BODY_DATA:
+               buf = soup_message_body_flatten (msg->request_body);
+               g_value_take_boxed (value, soup_buffer_get_as_bytes (buf));
+               soup_buffer_free (buf);
+               break;
        case PROP_REQUEST_HEADERS:
                g_value_set_boxed (value, msg->request_headers);
                break;
        case PROP_RESPONSE_BODY:
                g_value_set_boxed (value, msg->response_body);
                break;
+       case PROP_RESPONSE_BODY_DATA:
+               buf = soup_message_body_flatten (msg->response_body);
+               g_value_take_boxed (value, soup_buffer_get_as_bytes (buf));
+               soup_buffer_free (buf);
+               break;
        case PROP_RESPONSE_HEADERS:
                g_value_set_boxed (value, msg->response_headers);
                break;
@@ -784,6 +797,28 @@ soup_message_class_init (SoupMessageClass *message_class)
                                    SOUP_TYPE_MESSAGE_BODY,
                                    G_PARAM_READABLE));
        /**
+        * SOUP_MESSAGE_REQUEST_BODY_DATA:
+        *
+        * Alias for the #SoupMessage:request-body-data property. (The
+        * message's HTTP request body, as a #GBytes.)
+        *
+        * Since: 2.46
+        **/
+       /**
+        * SoupMessage:request-body-data:
+        *
+        * The message's HTTP request body, as a #GBytes.
+        *
+        * Since: 2.46
+        **/
+       g_object_class_install_property (
+               object_class, PROP_REQUEST_BODY_DATA,
+               g_param_spec_boxed (SOUP_MESSAGE_REQUEST_BODY_DATA,
+                                   "Request Body Data",
+                                   "The HTTP request body",
+                                   G_TYPE_BYTES,
+                                   G_PARAM_READABLE));
+       /**
         * SOUP_MESSAGE_REQUEST_HEADERS:
         *
         * Alias for the #SoupMessage:request-headers property. (The
@@ -810,6 +845,28 @@ soup_message_class_init (SoupMessageClass *message_class)
                                    SOUP_TYPE_MESSAGE_BODY,
                                    G_PARAM_READABLE));
        /**
+        * SOUP_MESSAGE_RESPONSE_BODY_DATA:
+        *
+        * Alias for the #SoupMessage:response-body-data property. (The
+        * message's HTTP response body, as a #GBytes.)
+        *
+        * Since: 2.46
+        **/
+       /**
+        * SoupMessage:response-body-data:
+        *
+        * The message's HTTP response body, as a #GBytes.
+        *
+        * Since: 2.46
+        **/
+       g_object_class_install_property (
+               object_class, PROP_RESPONSE_BODY_DATA,
+               g_param_spec_boxed (SOUP_MESSAGE_RESPONSE_BODY_DATA,
+                                   "Response Body Data",
+                                   "The HTTP response body",
+                                   G_TYPE_BYTES,
+                                   G_PARAM_READABLE));
+       /**
         * SOUP_MESSAGE_RESPONSE_HEADERS:
         *
         * Alias for the #SoupMessage:response-headers property. (The
diff --git a/libsoup/soup-message.h b/libsoup/soup-message.h
index 22c2b1e..b02d293 100644
--- a/libsoup/soup-message.h
+++ b/libsoup/soup-message.h
@@ -60,21 +60,23 @@ typedef struct {
 
 GType soup_message_get_type (void);
 
-#define SOUP_MESSAGE_METHOD           "method"
-#define SOUP_MESSAGE_URI              "uri"
-#define SOUP_MESSAGE_HTTP_VERSION     "http-version"
-#define SOUP_MESSAGE_FLAGS            "flags"
-#define SOUP_MESSAGE_SERVER_SIDE      "server-side"
-#define SOUP_MESSAGE_STATUS_CODE      "status-code"
-#define SOUP_MESSAGE_REASON_PHRASE    "reason-phrase"
-#define SOUP_MESSAGE_FIRST_PARTY      "first-party"
-#define SOUP_MESSAGE_REQUEST_BODY     "request-body"
-#define SOUP_MESSAGE_REQUEST_HEADERS  "request-headers"
-#define SOUP_MESSAGE_RESPONSE_BODY    "response-body"
-#define SOUP_MESSAGE_RESPONSE_HEADERS "response-headers"
-#define SOUP_MESSAGE_TLS_CERTIFICATE  "tls-certificate"
-#define SOUP_MESSAGE_TLS_ERRORS       "tls-errors"
-#define SOUP_MESSAGE_PRIORITY         "priority"
+#define SOUP_MESSAGE_METHOD             "method"
+#define SOUP_MESSAGE_URI                "uri"
+#define SOUP_MESSAGE_HTTP_VERSION       "http-version"
+#define SOUP_MESSAGE_FLAGS              "flags"
+#define SOUP_MESSAGE_SERVER_SIDE        "server-side"
+#define SOUP_MESSAGE_STATUS_CODE        "status-code"
+#define SOUP_MESSAGE_REASON_PHRASE      "reason-phrase"
+#define SOUP_MESSAGE_FIRST_PARTY        "first-party"
+#define SOUP_MESSAGE_REQUEST_BODY       "request-body"
+#define SOUP_MESSAGE_REQUEST_BODY_DATA  "request-body-data"
+#define SOUP_MESSAGE_REQUEST_HEADERS    "request-headers"
+#define SOUP_MESSAGE_RESPONSE_BODY      "response-body"
+#define SOUP_MESSAGE_RESPONSE_BODY_DATA "response-body-data"
+#define SOUP_MESSAGE_RESPONSE_HEADERS   "response-headers"
+#define SOUP_MESSAGE_TLS_CERTIFICATE    "tls-certificate"
+#define SOUP_MESSAGE_TLS_ERRORS         "tls-errors"
+#define SOUP_MESSAGE_PRIORITY           "priority"
 
 SoupMessage   *soup_message_new                 (const char        *method,
                                                 const char        *uri_string);


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