[libsoup/carlosgc/request-body-stream: 2/4] Stop using soup_message_set_request
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/carlosgc/request-body-stream: 2/4] Stop using soup_message_set_request
- Date: Thu, 8 Oct 2020 14:22:11 +0000 (UTC)
commit e7e602c879249e9d94535e1203c6fb8e9016e142
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Tue Oct 6 15:01:06 2020 +0200
Stop using soup_message_set_request
Use soup_message_set_request_body() or
soup_message_set_request_body_from_bytes() instead.
libsoup/soup-form.c | 9 +++++----
libsoup/soup-session.c | 3 +--
tests/continue-test.c | 36 ++++++++++++++++++++++++------------
tests/redirect-test.c | 18 ++++++++++--------
tests/server-test.c | 3 ++-
5 files changed, 42 insertions(+), 27 deletions(-)
---
diff --git a/libsoup/soup-form.c b/libsoup/soup-form.c
index 32f1c38e..84acf486 100644
--- a/libsoup/soup-form.c
+++ b/libsoup/soup-form.c
@@ -370,12 +370,13 @@ soup_form_request_for_data (const char *method, const char *uri_string,
msg = soup_message_new_from_uri (method, uri);
} else if (!strcmp (method, "POST") || !strcmp (method, "PUT")) {
+ GBytes *body;
+
msg = soup_message_new_from_uri (method, uri);
- soup_message_set_request (
- msg, SOUP_FORM_MIME_TYPE_URLENCODED,
- SOUP_MEMORY_TAKE,
- form_data, strlen (form_data));
+ body = g_bytes_new_take (form_data, strlen (form_data));
+ soup_message_set_request_body_from_bytes (msg, SOUP_FORM_MIME_TYPE_URLENCODED, body);
+ g_bytes_unref (body);
} else {
g_warning ("invalid method passed to soup_form_request_new");
g_free (form_data);
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index c674cbfe..ce7dc713 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -904,8 +904,7 @@ soup_session_redirect_message (SoupSession *session, SoupMessage *msg)
SOUP_MESSAGE_METHOD, SOUP_METHOD_GET,
NULL);
}
- soup_message_set_request (msg, NULL,
- SOUP_MEMORY_STATIC, NULL, 0);
+ soup_message_set_request_body (msg, NULL, NULL, 0);
soup_message_headers_set_encoding (msg->request_headers,
SOUP_ENCODING_NONE);
}
diff --git a/tests/continue-test.c b/tests/continue-test.c
index 0c891b77..85d1a4e6 100644
--- a/tests/continue-test.c
+++ b/tests/continue-test.c
@@ -46,6 +46,13 @@ EVENT_HANDLER (wrote_headers)
EVENT_HANDLER (wrote_body)
EVENT_HANDLER (finished)
+static void
+restarted (SoupMessage *msg,
+ GBytes *body)
+{
+ soup_message_set_request_body_from_bytes (msg, "text/plain", body);
+}
+
static void
do_message (const char *path, gboolean long_body,
gboolean expect_continue, gboolean auth,
@@ -59,6 +66,7 @@ do_message (const char *path, gboolean long_body,
const char *expected_event;
char *actual_event;
int expected_status, actual_status;
+ GBytes *request_body;
GBytes *response_body;
uri = soup_uri_copy (base_uri);
@@ -68,11 +76,12 @@ do_message (const char *path, gboolean long_body,
}
soup_uri_set_path (uri, path);
msg = soup_message_new_from_uri ("POST", uri);
+ g_print ("DBG: soup_message_new_from_uri: %p\n", msg);
soup_uri_free (uri);
body = long_body ? LONG_BODY : SHORT_BODY;
- soup_message_set_request (msg, "text/plain", SOUP_MEMORY_STATIC,
- body, strlen (body));
+ request_body = g_bytes_new_static (body, strlen (body));
+ soup_message_set_request_body_from_bytes (msg, "text/plain", request_body);
soup_message_headers_append (msg->request_headers, "Connection", "close");
if (expect_continue) {
soup_message_headers_set_expectations (msg->request_headers,
@@ -93,6 +102,8 @@ do_message (const char *path, gboolean long_body,
G_CALLBACK (wrote_body), "client");
g_signal_connect (msg, "finished",
G_CALLBACK (finished), "client");
+ g_signal_connect (msg, "restarted",
+ G_CALLBACK (restarted), request_body);
events = NULL;
session = soup_test_session_new (SOUP_TYPE_SESSION, NULL);
@@ -149,6 +160,7 @@ do_message (const char *path, gboolean long_body,
!strcmp (actual_event, "server-wrote_informational"))
events = g_slist_delete_link (events, events);
}
+ g_bytes_unref (request_body);
g_bytes_unref (response_body);
g_object_unref (msg);
}
@@ -158,12 +170,12 @@ do_test_unauth_short_noexpect_nopass (void)
{
do_message ("/unauth", FALSE, FALSE, FALSE,
"client-wrote_headers",
- "client-wrote_body",
"server-got_headers",
"server-got_body",
"server-wrote_headers", SOUP_STATUS_CREATED,
"server-wrote_body",
"server-finished",
+ "client-wrote_body",
"client-got_headers",
"client-got_body",
"client-finished",
@@ -175,12 +187,12 @@ do_test_unauth_long_noexpect_nopass (void)
{
do_message ("/unauth", TRUE, FALSE, FALSE,
"client-wrote_headers",
- "client-wrote_body",
"server-got_headers",
"server-got_body",
"server-wrote_headers", SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE,
"server-wrote_body",
"server-finished",
+ "client-wrote_body",
"client-got_headers",
"client-got_body",
"client-finished",
@@ -195,11 +207,11 @@ do_test_unauth_short_expect_nopass (void)
"server-got_headers",
"server-wrote_informational", SOUP_STATUS_CONTINUE,
"client-got_informational",
- "client-wrote_body",
"server-got_body",
"server-wrote_headers", SOUP_STATUS_CREATED,
"server-wrote_body",
"server-finished",
+ "client-wrote_body",
"client-got_headers",
"client-got_body",
"client-finished",
@@ -226,12 +238,12 @@ do_test_auth_short_noexpect_nopass (void)
{
do_message ("/auth", FALSE, FALSE, FALSE,
"client-wrote_headers",
- "client-wrote_body",
"server-got_headers",
"server-got_body",
"server-wrote_headers", SOUP_STATUS_UNAUTHORIZED,
"server-wrote_body",
"server-finished",
+ "client-wrote_body",
"client-got_headers",
"client-got_body",
"client-finished",
@@ -243,12 +255,12 @@ do_test_auth_long_noexpect_nopass (void)
{
do_message ("/auth", TRUE, FALSE, FALSE,
"client-wrote_headers",
- "client-wrote_body",
"server-got_headers",
"server-got_body",
"server-wrote_headers", SOUP_STATUS_UNAUTHORIZED,
"server-wrote_body",
"server-finished",
+ "client-wrote_body",
"client-got_headers",
"client-got_body",
"client-finished",
@@ -290,21 +302,21 @@ do_test_auth_short_noexpect_pass (void)
{
do_message ("/auth", FALSE, FALSE, TRUE,
"client-wrote_headers",
- "client-wrote_body",
"server-got_headers",
"server-got_body",
"server-wrote_headers", SOUP_STATUS_UNAUTHORIZED,
"server-wrote_body",
"server-finished",
+ "client-wrote_body",
"client-got_headers",
"client-got_body",
"client-wrote_headers",
- "client-wrote_body",
"server-got_headers",
"server-got_body",
"server-wrote_headers", SOUP_STATUS_CREATED,
"server-wrote_body",
"server-finished",
+ "client-wrote_body",
"client-got_headers",
"client-got_body",
"client-finished",
@@ -316,21 +328,21 @@ do_test_auth_long_noexpect_pass (void)
{
do_message ("/auth", TRUE, FALSE, TRUE,
"client-wrote_headers",
- "client-wrote_body",
"server-got_headers",
"server-got_body",
"server-wrote_headers", SOUP_STATUS_UNAUTHORIZED,
"server-wrote_body",
"server-finished",
+ "client-wrote_body",
"client-got_headers",
"client-got_body",
"client-wrote_headers",
- "client-wrote_body",
"server-got_headers",
"server-got_body",
"server-wrote_headers", SOUP_STATUS_REQUEST_ENTITY_TOO_LARGE,
"server-wrote_body",
"server-finished",
+ "client-wrote_body",
"client-got_headers",
"client-got_body",
"client-finished",
@@ -352,11 +364,11 @@ do_test_auth_short_expect_pass (void)
"server-got_headers",
"server-wrote_informational", SOUP_STATUS_CONTINUE,
"client-got_informational",
- "client-wrote_body",
"server-got_body",
"server-wrote_headers", SOUP_STATUS_CREATED,
"server-wrote_body",
"server-finished",
+ "client-wrote_body",
"client-got_headers",
"client-got_body",
"client-finished",
diff --git a/tests/redirect-test.c b/tests/redirect-test.c
index 66b1a2d0..d360065a 100644
--- a/tests/redirect-test.c
+++ b/tests/redirect-test.c
@@ -173,10 +173,11 @@ do_message_api_test (SoupSession *session, TestCase *test)
soup_uri_free (uri);
if (msg->method == SOUP_METHOD_POST) {
- soup_message_set_request (msg, "text/plain",
- SOUP_MEMORY_STATIC,
- "post body",
- strlen ("post body"));
+ GBytes *request_body;
+
+ request_body = g_bytes_new_static ("post body", strlen ("post body"));
+ soup_message_set_request_body_from_bytes (msg, "text/plain", request_body);
+ g_bytes_unref (request_body);
}
treq = &test->requests[0];
@@ -219,10 +220,11 @@ do_request_api_test (SoupSession *session, TestCase *test)
msg = soup_request_http_get_message (reqh);
if (msg->method == SOUP_METHOD_POST) {
- soup_message_set_request (msg, "text/plain",
- SOUP_MEMORY_STATIC,
- "post body",
- strlen ("post body"));
+ GBytes *request_body;
+
+ request_body = g_bytes_new_static ("post body", strlen ("post body"));
+ soup_message_set_request_body_from_bytes (msg, "text/plain", request_body);
+ g_bytes_unref (request_body);
}
treq = &test->requests[0];
diff --git a/tests/server-test.c b/tests/server-test.c
index 77f4b763..461aef21 100644
--- a/tests/server-test.c
+++ b/tests/server-test.c
@@ -1003,7 +1003,7 @@ do_early_stream_test (ServerData *sd, gconstpointer test_data)
msg = soup_message_new_from_uri ("POST", sd->base_uri);
index = soup_test_get_index ();
- soup_message_body_append_bytes (msg->request_body, index);
+ soup_message_set_request_body_from_bytes (msg, "text/plain", index);
body = soup_test_session_send (session, msg, NULL, NULL);
soup_test_assert_message_status (msg, SOUP_STATUS_OK);
@@ -1012,6 +1012,7 @@ do_early_stream_test (ServerData *sd, gconstpointer test_data)
g_assert_cmpmem (md5, strlen (md5), g_bytes_get_data (body, NULL), g_bytes_get_size (body));
g_free (md5);
+ g_bytes_unref (index);
g_bytes_unref (body);
g_object_unref (msg);
soup_test_session_abort_unref (session);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]