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 | |
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.
-rw-r--r-- | docs/reference/libsoup-3.0-sections.txt | 3 | ||||
-rw-r--r-- | libsoup/soup-session.c | 154 | ||||
-rw-r--r-- | libsoup/soup-session.h | 46 | ||||
-rw-r--r-- | tests/coding-test.c | 22 | ||||
-rw-r--r-- | tests/connection-test.c | 14 | ||||
-rw-r--r-- | tests/forms-test.c | 4 | ||||
-rw-r--r-- | tests/hsts-db-test.c | 2 | ||||
-rw-r--r-- | tests/hsts-test.c | 2 | ||||
-rw-r--r-- | tests/misc-test.c | 4 | ||||
-rw-r--r-- | tests/ntlm-test.c | 6 | ||||
-rw-r--r-- | tests/server-test.c | 6 | ||||
-rw-r--r-- | tests/session-test.c | 4 | ||||
-rw-r--r-- | tests/ssl-test.c | 2 | ||||
-rw-r--r-- | tests/test-utils.c | 55 | ||||
-rw-r--r-- | tests/test-utils.h | 4 |
15 files changed, 228 insertions, 100 deletions
diff --git a/docs/reference/libsoup-3.0-sections.txt b/docs/reference/libsoup-3.0-sections.txt index 294301e5..d6802198 100644 --- a/docs/reference/libsoup-3.0-sections.txt +++ b/docs/reference/libsoup-3.0-sections.txt @@ -387,6 +387,9 @@ soup_session_get_accept_language_auto soup_session_send soup_session_send_async soup_session_send_finish +soup_session_send_and_read +soup_session_send_and_read_async +soup_session_send_and_read_finish <SUBSECTION> soup_session_read_uri soup_session_read_uri_async diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c index 1234e500..dac80502 100644 --- a/libsoup/soup-session.c +++ b/libsoup/soup-session.c @@ -3282,6 +3282,160 @@ soup_session_send (SoupSession *session, return stream; } +static void +send_and_read_splice_ready_cb (GOutputStream *ostream, + GAsyncResult *result, + GTask *task) +{ + GError *error = NULL; + + if (g_output_stream_splice_finish (ostream, result, &error) != -1) { + g_task_return_pointer (task, + g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (ostream)), + (GDestroyNotify)g_bytes_unref); + } else { + g_task_return_error (task, error); + } + g_object_unref (task); +} + +static void +send_and_read_stream_ready_cb (SoupSession *session, + GAsyncResult *result, + GTask *task) +{ + GInputStream *stream; + GOutputStream *ostream; + GError *error = NULL; + + stream = soup_session_send_finish (session, result, &error); + if (!stream) { + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); + g_output_stream_splice_async (ostream, + stream, + G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | + G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, + g_task_get_priority (task), + g_task_get_cancellable (task), + (GAsyncReadyCallback)send_and_read_splice_ready_cb, + task); + g_object_unref (ostream); + g_object_unref (stream); +} + +/** + * soup_session_send_and_read_async: + * @session: a #SoupSession + * @msg: a #SoupMessage + * @io_priority: the I/O priority of the request + * @cancellable: a #GCancellable + * @callback: the callback to invoke + * @user_data: data for @callback + * + * Asynchronously sends @msg and reads the response body. + * When @callback is called, then either @msg has been sent, and its response + * body read, or else an error has occurred. + * This function should only be used when the resource to be retrieved + * is not too long and can be stored in memory. + * Call soup_session_send_and_read_finish() to get a #GBytes with the + * response body. + * + * See soup_session_send() for more details on the general semantics. + */ +void +soup_session_send_and_read_async (SoupSession *session, + SoupMessage *msg, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GTask *task; + + g_return_if_fail (SOUP_IS_SESSION (session)); + g_return_if_fail (SOUP_IS_MESSAGE (msg)); + + task = g_task_new (session, cancellable, callback, user_data); + g_task_set_priority (task, io_priority); + + soup_session_send_async (session, msg, + g_task_get_priority (task), + g_task_get_cancellable (task), + (GAsyncReadyCallback)send_and_read_stream_ready_cb, + task); +} + +/** + * soup_session_send_and_read_finish: + * @session: a #SoupSession + * @result: the #GAsyncResult passed to your callback + * @error: return location for a #GError, or %NULL + * + * Gets the response to a soup_session_send_and_read_async() call and (if + * successful), returns a #GBytes with the response body. + * + * Returns: (transfer full): a #GBytes, or %NULL on error. + */ +GBytes * +soup_session_send_and_read_finish (SoupSession *session, + GAsyncResult *result, + GError **error) +{ + g_return_val_if_fail (SOUP_IS_SESSION (session), NULL); + g_return_val_if_fail (g_task_is_valid (result, session), NULL); + + return g_task_propagate_pointer (G_TASK (result), error); +} + +/** + * soup_session_send_and_read: + * @session: a #SoupSession + * @msg: a #SoupMessage + * @cancellable: a #GCancellable + * @error: return location for a #GError, or %NULL + * + * Synchronously sends @msg and reads the response body. + * On success, a #GBytes will be returned with the response body. + * This function should only be used when the resource to be retrieved + * is not too long and can be stored in memory. + * + * See soup_session_send() for more details on the general semantics. + * + * Returns: (transfer full): a #GBytes, or %NULL on error. + */ +GBytes * +soup_session_send_and_read (SoupSession *session, + SoupMessage *msg, + GCancellable *cancellable, + GError **error) +{ + GInputStream *stream; + GOutputStream *ostream; + GBytes *bytes = NULL; + + stream = soup_session_send (session, msg, cancellable, error); + if (!stream) + return NULL; + + ostream = g_memory_output_stream_new (NULL, 0, g_realloc, g_free); + if (g_output_stream_splice (ostream, + stream, + G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE | + G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, + cancellable, error) != -1) { + bytes = g_memory_output_stream_steal_as_bytes (G_MEMORY_OUTPUT_STREAM (ostream)); + } + g_object_unref (ostream); + g_object_unref (stream); + + return bytes; +} + typedef struct { goffset content_length; char *content_type; diff --git a/libsoup/soup-session.h b/libsoup/soup-session.h index 069443b1..e8574483 100644 --- a/libsoup/soup-session.h +++ b/libsoup/soup-session.h @@ -103,24 +103,42 @@ SOUP_AVAILABLE_IN_ALL gboolean soup_session_get_accept_language_auto (SoupSession *session); SOUP_AVAILABLE_IN_ALL -void soup_session_abort (SoupSession *session); +void soup_session_abort (SoupSession *session); SOUP_AVAILABLE_IN_ALL -void soup_session_send_async (SoupSession *session, - SoupMessage *msg, - int io_priority, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); +void soup_session_send_async (SoupSession *session, + SoupMessage *msg, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); SOUP_AVAILABLE_IN_ALL -GInputStream *soup_session_send_finish (SoupSession *session, - GAsyncResult *result, - GError **error); +GInputStream *soup_session_send_finish (SoupSession *session, + GAsyncResult *result, + GError **error); SOUP_AVAILABLE_IN_ALL -GInputStream *soup_session_send (SoupSession *session, - SoupMessage *msg, - GCancellable *cancellable, - GError **error) G_GNUC_WARN_UNUSED_RESULT; +GInputStream *soup_session_send (SoupSession *session, + SoupMessage *msg, + GCancellable *cancellable, + GError **error) G_GNUC_WARN_UNUSED_RESULT; +SOUP_AVAILABLE_IN_ALL +void soup_session_send_and_read_async (SoupSession *session, + SoupMessage *msg, + int io_priority, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + +SOUP_AVAILABLE_IN_ALL +GBytes *soup_session_send_and_read_finish (SoupSession *session, + GAsyncResult *result, + GError **error); + +SOUP_AVAILABLE_IN_ALL +GBytes *soup_session_send_and_read (SoupSession *session, + SoupMessage *msg, + GCancellable *cancellable, + GError **error); SOUP_AVAILABLE_IN_ALL void soup_session_add_feature (SoupSession *session, diff --git a/tests/coding-test.c b/tests/coding-test.c index 0a1d553c..701086a2 100644 --- a/tests/coding-test.c +++ b/tests/coding-test.c @@ -171,7 +171,7 @@ setup_coding_test (CodingTestData *data, gconstpointer test_data) data->response = g_bytes_new_static (NULL, 0); else { msg = soup_message_new_from_uri ("GET", uri); - data->response = soup_test_session_send (data->session, msg, NULL, NULL); + data->response = soup_session_send_and_read (data->session, msg, NULL, NULL); g_object_unref (msg); } @@ -196,7 +196,7 @@ do_coding_test_plain (CodingTestData *data, gconstpointer test_data) { GBytes *body; - body = soup_test_session_send (data->session, data->msg, NULL, NULL); + body = soup_session_send_and_read (data->session, data->msg, NULL, NULL); check_response (data, NULL, "text/plain", body); g_bytes_unref (body); } @@ -206,7 +206,7 @@ do_coding_test_gzip (CodingTestData *data, gconstpointer test_data) { GBytes *body; - body = soup_test_session_send (data->session, data->msg, NULL, NULL); + body = soup_session_send_and_read (data->session, data->msg, NULL, NULL); check_response (data, "gzip", "text/plain", body); g_bytes_unref (body); } @@ -222,7 +222,7 @@ do_coding_test_gzip_with_junk (CodingTestData *data, gconstpointer test_data) soup_message_headers_append (soup_message_get_request_headers (data->msg), "X-Test-Options", "trailing-junk"); - body = soup_test_session_send (data->session, data->msg, NULL, NULL); + body = soup_session_send_and_read (data->session, data->msg, NULL, NULL); check_response (data, "gzip", "text/plain", body); g_bytes_unref (body); } @@ -237,7 +237,7 @@ do_coding_test_gzip_bad_server (CodingTestData *data, gconstpointer test_data) soup_message_headers_append (soup_message_get_request_headers (data->msg), "X-Test-Options", "force-encode"); - body = soup_test_session_send (data->session, data->msg, NULL, NULL); + body = soup_session_send_and_read (data->session, data->msg, NULL, NULL); /* Failed content-decoding should have left the body untouched * from what the server sent... which happens to be the @@ -254,7 +254,7 @@ do_coding_test_deflate (CodingTestData *data, gconstpointer test_data) soup_message_headers_append (soup_message_get_request_headers (data->msg), "X-Test-Options", "prefer-deflate-zlib"); - body = soup_test_session_send (data->session, data->msg, NULL, NULL); + body = soup_session_send_and_read (data->session, data->msg, NULL, NULL); check_response (data, "deflate", "text/plain", body); g_bytes_unref (body); } @@ -269,7 +269,7 @@ do_coding_test_deflate_with_junk (CodingTestData *data, gconstpointer test_data) soup_message_headers_append (soup_message_get_request_headers (data->msg), "X-Test-Options", "prefer-deflate-zlib, trailing-junk"); - body = soup_test_session_send (data->session, data->msg, NULL, NULL); + body = soup_session_send_and_read (data->session, data->msg, NULL, NULL); check_response (data, "deflate", "text/plain", body); g_bytes_unref (body); } @@ -283,7 +283,7 @@ do_coding_test_deflate_bad_server (CodingTestData *data, gconstpointer test_data soup_message_headers_append (soup_message_get_request_headers (data->msg), "X-Test-Options", "force-encode, prefer-deflate-zlib"); - body = soup_test_session_send (data->session, data->msg, NULL, NULL); + body = soup_session_send_and_read (data->session, data->msg, NULL, NULL); check_response (data, "deflate", "text/plain", body); g_bytes_unref (body); } @@ -295,7 +295,7 @@ do_coding_test_deflate_raw (CodingTestData *data, gconstpointer test_data) soup_message_headers_append (soup_message_get_request_headers (data->msg), "X-Test-Options", "prefer-deflate-raw"); - body = soup_test_session_send (data->session, data->msg, NULL, NULL); + body = soup_session_send_and_read (data->session, data->msg, NULL, NULL); check_response (data, "deflate", "text/plain", body); g_bytes_unref (body); } @@ -309,7 +309,7 @@ do_coding_test_deflate_raw_bad_server (CodingTestData *data, gconstpointer test_ soup_message_headers_append (soup_message_get_request_headers (data->msg), "X-Test-Options", "force-encode, prefer-deflate-raw"); - body = soup_test_session_send (data->session, data->msg, NULL, NULL); + body = soup_session_send_and_read (data->session, data->msg, NULL, NULL); check_response (data, "deflate", "text/plain", body); g_bytes_unref (body); } @@ -323,7 +323,7 @@ do_coding_msg_empty_test (CodingTestData *data, gconstpointer test_data) soup_message_headers_append (soup_message_get_request_headers (data->msg), "X-Test-Options", "empty"); - body = soup_test_session_send (data->session, data->msg, NULL, NULL); + body = soup_session_send_and_read (data->session, data->msg, NULL, NULL); check_response (data, "gzip", "text/plain", body); g_bytes_unref (body); } diff --git a/tests/connection-test.c b/tests/connection-test.c index 12359252..d4ddb8e2 100644 --- a/tests/connection-test.c +++ b/tests/connection-test.c @@ -194,7 +194,7 @@ do_content_length_framing_test (void) debug_printf (1, " Content-Length larger than message body length\n"); request_uri = g_uri_parse_relative (base_uri, "/content-length/long", SOUP_HTTP_URI_FLAGS, NULL); msg = soup_message_new_from_uri ("GET", request_uri); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); @@ -210,7 +210,7 @@ do_content_length_framing_test (void) debug_printf (1, " Server claims 'Connection: close' but doesn't\n"); request_uri = g_uri_parse_relative (base_uri, "/content-length/noclose", SOUP_HTTP_URI_FLAGS, NULL); msg = soup_message_new_from_uri ("GET", request_uri); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); @@ -276,7 +276,7 @@ do_timeout_test_for_session (SoupSession *session) timeout_uri = g_uri_parse_relative (base_uri, "/timeout-persistent", SOUP_HTTP_URI_FLAGS, NULL); msg = soup_message_new_from_uri ("GET", timeout_uri); g_uri_unref (timeout_uri); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); if (sockets[1]) { @@ -294,7 +294,7 @@ do_timeout_test_for_session (SoupSession *session) debug_printf (1, " Second message\n"); msg = soup_message_new_from_uri ("GET", base_uri); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); soup_test_assert (sockets[1] == sockets[0], @@ -626,7 +626,7 @@ do_non_idempotent_test_for_session (SoupSession *session) debug_printf (2, " GET\n"); msg = soup_message_new_from_uri ("GET", base_uri); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); if (sockets[1]) { soup_test_assert (sockets[1] == NULL, "Message was retried"); @@ -637,7 +637,7 @@ do_non_idempotent_test_for_session (SoupSession *session) debug_printf (2, " POST\n"); msg = soup_message_new_from_uri ("POST", base_uri); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); soup_test_assert (sockets[1] != sockets[0], "Message was sent on existing connection"); @@ -861,7 +861,7 @@ do_one_connection_event_test (SoupSession *session, const char *uri, g_signal_connect (msg, "network-event", G_CALLBACK (network_event), &events); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); while (*events) { soup_test_assert (!*events, diff --git a/tests/forms-test.c b/tests/forms-test.c index 8dbdbe54..052b71d6 100644 --- a/tests/forms-test.c +++ b/tests/forms-test.c @@ -132,7 +132,7 @@ do_hello_test_libsoup (int n, gboolean extra, const char *uri) g_free (encoded); g_datalist_clear (&data); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); g_assert_cmpmem (tests[n].result, strlen (tests[n].result), g_bytes_get_data (body, NULL), g_bytes_get_size (body)); @@ -259,7 +259,7 @@ do_md5_test_libsoup (gconstpointer data) soup_multipart_free (multipart); session = soup_test_session_new (NULL); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); g_assert_cmpmem (md5, strlen (md5), g_bytes_get_data (body, NULL), g_bytes_get_size (body)); diff --git a/tests/hsts-db-test.c b/tests/hsts-db-test.c index 8700e12b..1149a044 100644 --- a/tests/hsts-db-test.c +++ b/tests/hsts-db-test.c @@ -80,7 +80,7 @@ session_get_uri (SoupSession *session, msg = soup_message_new ("GET", uri); g_signal_connect (msg, "hsts-enforced", G_CALLBACK (hsts_enforced_cb), &enforced); soup_message_add_flags (msg, SOUP_MESSAGE_NO_REDIRECT); - body = soup_test_session_send (session, msg, NULL, &error); + body = soup_session_send_and_read (session, msg, NULL, &error); if (expected_status == SOUP_STATUS_NONE) g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE); else diff --git a/tests/hsts-test.c b/tests/hsts-test.c index bc87d4c5..35c3bb3d 100644 --- a/tests/hsts-test.c +++ b/tests/hsts-test.c @@ -126,7 +126,7 @@ session_get_uri (SoupSession *session, msg = soup_message_new ("GET", uri); g_signal_connect (msg, "hsts-enforced", G_CALLBACK (hsts_enforced_cb), &enforced); soup_message_add_flags (msg, SOUP_MESSAGE_NO_REDIRECT); - body = soup_test_session_send (session, msg, NULL, &error); + body = soup_session_send_and_read (session, msg, NULL, &error); if (expected_status == SOUP_STATUS_NONE) g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE); else diff --git a/tests/misc-test.c b/tests/misc-test.c index 7cee459a..cf1b8855 100644 --- a/tests/misc-test.c +++ b/tests/misc-test.c @@ -85,8 +85,8 @@ do_host_test (void) two = soup_message_new_from_uri ("GET", base_uri); soup_message_headers_replace (soup_message_get_request_headers (two), "Host", "foo"); - body_one = soup_test_session_send (session, one, NULL, NULL); - body_two = soup_test_session_send (session, two, NULL, NULL); + body_one = soup_session_send_and_read (session, one, NULL, NULL); + body_two = soup_session_send_and_read (session, two, NULL, NULL); soup_test_session_abort_unref (session); diff --git a/tests/ntlm-test.c b/tests/ntlm-test.c index a40ebd37..3f6366ad 100644 --- a/tests/ntlm-test.c +++ b/tests/ntlm-test.c @@ -350,7 +350,7 @@ do_message (SoupSession *session, g_signal_connect (msg, "wrote-headers", G_CALLBACK (response_check), &state); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); debug_printf (1, " %-10s -> ", path); if (state.got_ntlm_prompt) { @@ -681,7 +681,7 @@ do_retrying_test (TestServer *ts, G_CALLBACK (retry_test_authenticate), &retried); g_uri_unref (uri); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); g_assert_true (retried); soup_test_assert_message_status (msg, SOUP_STATUS_OK); @@ -703,7 +703,7 @@ do_retrying_test (TestServer *ts, G_CALLBACK (retry_test_authenticate), &retried); g_uri_unref (uri); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); g_assert_true (retried); soup_test_assert_message_status (msg, SOUP_STATUS_UNAUTHORIZED); diff --git a/tests/server-test.c b/tests/server-test.c index 8be65bfe..f0bc8ef0 100644 --- a/tests/server-test.c +++ b/tests/server-test.c @@ -903,7 +903,7 @@ do_early_stream_test (ServerData *sd, gconstpointer test_data) index = soup_test_get_index (); soup_message_set_request_body_from_bytes (msg, "text/plain", index); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); @@ -948,7 +948,7 @@ do_early_respond_test (ServerData *sd, gconstpointer test_data) /* The early handler will ignore this one */ uri2 = g_uri_parse_relative (sd->base_uri, "/subdir", SOUP_HTTP_URI_FLAGS, NULL); msg = soup_message_new_from_uri ("GET", uri2); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); soup_test_assert_message_status (msg, SOUP_STATUS_OK); g_assert_cmpmem ("index", sizeof ("index") - 1, g_bytes_get_data (body, NULL), g_bytes_get_size (body)); g_bytes_unref (body); @@ -1008,7 +1008,7 @@ do_early_multi_test (ServerData *sd, gconstpointer test_data) msg = soup_message_new_from_uri ("GET", uri); g_uri_unref (uri); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); /* The normal handler sets status to OK. The early handler doesn't * touch status, meaning that if it runs and the normal handler doesn't, diff --git a/tests/session-test.c b/tests/session-test.c index ab040c00..6d25f7d0 100644 --- a/tests/session-test.c +++ b/tests/session-test.c @@ -89,7 +89,7 @@ do_test_for_session (SoupSession *session, debug_printf (2, " requesting timeout\n"); timeout_uri = g_uri_parse_relative (base_uri, "/request-timeout", SOUP_HTTP_URI_FLAGS, NULL); msg = soup_message_new_from_uri ("GET", timeout_uri); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); g_bytes_unref (body); g_uri_unref (timeout_uri); @@ -121,7 +121,7 @@ do_test_for_session (SoupSession *session, msg = soup_message_new_from_uri ("GET", base_uri); server_processed_message = local_timeout = FALSE; timeout_id = g_idle_add_full (G_PRIORITY_HIGH, timeout_cb, &local_timeout, NULL); - body = soup_test_session_send (session, msg, NULL, NULL); + body = soup_session_send_and_read (session, msg, NULL, NULL); g_bytes_unref (body); g_object_unref (msg); diff --git a/tests/ssl-test.c b/tests/ssl-test.c index a1df8336..0958d5a2 100644 --- a/tests/ssl-test.c +++ b/tests/ssl-test.c @@ -57,7 +57,7 @@ do_strictness_test (gconstpointer data) g_signal_connect (msg, "accept-certificate", G_CALLBACK (accept_certificate), NULL); } - body = soup_test_session_send (session, msg, NULL, &error); + body = soup_session_send_and_read (session, msg, NULL, &error); soup_test_assert_message_status (msg, test->expected_status); if (test->expected_status != SOUP_STATUS_OK) g_assert_error (error, G_TLS_ERROR, G_TLS_ERROR_BAD_CERTIFICATE); 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) { diff --git a/tests/test-utils.h b/tests/test-utils.h index 7a155495..f3dc8798 100644 --- a/tests/test-utils.h +++ b/tests/test-utils.h @@ -90,10 +90,6 @@ gboolean soup_test_request_read_all (GInputStream *stream, gboolean soup_test_request_close_stream (GInputStream *stream, GCancellable *cancellable, GError **error); -GBytes *soup_test_session_send (SoupSession *session, - SoupMessage *msg, - GCancellable *cancellable, - GError **error); void soup_test_register_resources (void); GBytes *soup_test_load_resource (const char *name, |