summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Winship <danw@gnome.org>2013-08-25 11:05:44 -0400
committerDan Winship <danw@gnome.org>2013-11-17 09:49:01 -0500
commitd24e469c9a4e11a6ca05dab8b4c95d4d14186c75 (patch)
treec04b8c08a22f42f48e696b29a62fbde5fdb1ce27
parent16fa40768078ed676b6ffe6ad0f5334a273ed428 (diff)
downloadlibsoup-d24e469c9a4e11a6ca05dab8b4c95d4d14186c75.tar.gz
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
-rw-r--r--libsoup/soup-message.c57
-rw-r--r--libsoup/soup-message.h32
2 files changed, 74 insertions, 15 deletions
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index b51f234e..07967fc2 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 22c2b1ed..b02d293b 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);