diff options
author | Carlos Garcia Campos <cgarcia@igalia.com> | 2021-03-03 15:06:13 +0100 |
---|---|---|
committer | Carlos Garcia Campos <cgarcia@igalia.com> | 2021-03-03 15:31:28 +0100 |
commit | 7033879bcff9a7b1c31c086ed020fc8fa03fcd81 (patch) | |
tree | b6785cdf862eae326a504c756dbd93d25b2dcb03 /tests/test-utils.c | |
parent | d11e8bfa3cd300ca96d5387610a217b0aca87350 (diff) | |
download | libsoup-7033879bcff9a7b1c31c086ed020fc8fa03fcd81.tar.gz |
session: add soup_session_send_and_read APIscarlosgc/send_and_read
This is convenient API to send a message and read its body into a
GBytes. This should replace the basic APIs since it covers the same use
case, but using a SoupMessage instead of a URI and with ore flexibility.
Diffstat (limited to 'tests/test-utils.c')
-rw-r--r-- | tests/test-utils.c | 55 |
1 files changed, 6 insertions, 49 deletions
diff --git a/tests/test-utils.c b/tests/test-utils.c index accf79d1..8548a676 100644 --- a/tests/test-utils.c +++ b/tests/test-utils.c @@ -313,28 +313,12 @@ typedef struct { } SendAsyncData; static void -send_async_ready_cb (SoupSession *session, - GAsyncResult *result, - SendAsyncData *data) +send_and_read_async_ready_cb (SoupSession *session, + GAsyncResult *result, + SendAsyncData *data) { - GInputStream *istream; - GOutputStream *ostream; - data->done = TRUE; - istream = soup_session_send_finish (session, result, &data->error); - if (!istream) - return; - - ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); - g_output_stream_splice (ostream, - istream, - G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | - G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, - NULL, - &data->error); - data->body = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (ostream)); - g_object_unref (ostream); - g_object_unref (istream); + data->body = soup_session_send_and_read_finish (session, result, &data->error); } static void @@ -358,8 +342,8 @@ soup_test_session_async_send (SoupSession *session, signal_id = g_signal_connect (msg, "finished", G_CALLBACK (on_message_finished), &message_finished); - soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, cancellable, - (GAsyncReadyCallback)send_async_ready_cb, &data); + soup_session_send_and_read_async (session, msg, G_PRIORITY_DEFAULT, cancellable, + (GAsyncReadyCallback)send_and_read_async_ready_cb, &data); while (!data.done || !message_finished) g_main_context_iteration (async_context, TRUE); @@ -773,33 +757,6 @@ soup_test_request_close_stream (GInputStream *stream, return ok; } -GBytes * -soup_test_session_send (SoupSession *session, - SoupMessage *msg, - GCancellable *cancellable, - GError **error) -{ - GInputStream *istream; - GOutputStream *ostream; - GBytes *body; - - istream = soup_session_send (session, msg, cancellable, error); - if (!istream) - return NULL; - - ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); - g_output_stream_splice (ostream, - istream, - G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | - G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, - NULL, NULL); - body = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (ostream)); - g_object_unref (ostream); - g_object_unref (istream); - - return body; -} - void soup_test_register_resources (void) { |