[libsoup/pgriffis/updated-examples: 24/24] examples: Change get to use high level API
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/pgriffis/updated-examples: 24/24] examples: Change get to use high level API
- Date: Mon, 30 Nov 2020 22:08:45 +0000 (UTC)
commit 055baf57d9d1f07d5699cb17cbdb8baabf853135
Author: Patrick Griffis <pgriffis igalia com>
Date: Mon Nov 30 16:08:27 2020 -0600
examples: Change get to use high level API
examples/get.c | 32 ++++++--------------------------
1 file changed, 6 insertions(+), 26 deletions(-)
---
diff --git a/examples/get.c b/examples/get.c
index 5b8dd244..ddb929ee 100644
--- a/examples/get.c
+++ b/examples/get.c
@@ -15,7 +15,7 @@
static SoupSession *session;
static GMainLoop *loop;
-static gboolean debug, head, quiet;
+static gboolean debug, quiet;
static const gchar *output_file_path = NULL;
#define OUTPUT_BUFFER_SIZE 8192
@@ -70,8 +70,8 @@ static void
on_request_sent (GObject *source, GAsyncResult *result, gpointer user_data)
{
GError *error = NULL;
- SoupMessage *msg = user_data;
- GInputStream *in = soup_session_send_finish (SOUP_SESSION (source), result, &error);
+ GInputStream *in = soup_session_read_uri_finish (SOUP_SESSION (source), result,
+ NULL, NULL, &error);
if (error) {
g_printerr ("Failed to send request: %s\n", error->message);
@@ -80,18 +80,6 @@ on_request_sent (GObject *source, GAsyncResult *result, gpointer user_data)
return;
}
- if (!debug) {
- const char *path = g_uri_get_path (soup_message_get_uri (msg));
- g_print ("%s: %d %s\n", path, soup_message_get_status (msg),
- soup_message_get_reason_phrase (msg));
- }
-
- if (head || !SOUP_STATUS_IS_SUCCESSFUL (soup_message_get_status (msg))) {
- g_object_unref (in);
- g_main_loop_quit (loop);
- return;
- }
-
if (output_file_path) {
GFile *output_file = g_file_new_for_commandline_arg (output_file_path);
GOutputStream *out = G_OUTPUT_STREAM (g_file_create (output_file, G_FILE_CREATE_NONE,
@@ -194,9 +182,6 @@ static GOptionEntry entries[] = {
{ "debug", 'd', 0,
G_OPTION_ARG_NONE, &debug,
"Show HTTP headers", NULL },
- { "head", 'h', 0,
- G_OPTION_ARG_NONE, &head,
- "Do HEAD rather than GET", NULL },
{ "ntlm", 'n', 0,
G_OPTION_ARG_NONE, &ntlm,
"Use NTLM authentication", NULL },
@@ -225,7 +210,6 @@ main (int argc, char **argv)
GOptionContext *opts;
const char *url;
GUri *parsed;
- SoupMessage *msg;
GError *error = NULL;
opts = g_option_context_new (NULL);
@@ -329,19 +313,15 @@ main (int argc, char **argv)
g_object_unref (resolver);
}
- /* Send the message */
- msg = soup_message_new (head ? "HEAD" : "GET", url);
- /* Note that soup_session_read_uri_async() and soup_session_load_uri_bytes_async()
- are more simple APIs for common usage. This is a lower level example using
- SoupMessage */
- soup_session_send_async (session, msg, G_PRIORITY_DEFAULT, NULL, on_request_sent, msg);
+ /* Send the request */
+ soup_session_read_uri_async (session, url, G_PRIORITY_DEFAULT, NULL,
+ on_request_sent, NULL);
/* Run the loop */
loop = g_main_loop_new (NULL, FALSE);
g_main_loop_run (loop);
g_main_loop_unref (loop);
g_object_unref (session);
- g_object_unref (msg);
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]