summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Griffis <pgriffis@igalia.com>2020-11-30 16:08:27 -0600
committerPatrick Griffis <tingping@tingping.se>2020-12-13 19:32:41 +0000
commit9eb8f2faa5b8657804175ef5a50cffbc3c602754 (patch)
tree4a4ee328b627c020ff29ae5243bc667ac021e2d2
parent05c0418ae7dd458bb989ad26d54bda96aace31ae (diff)
downloadlibsoup-pgriffis/updated-examples.tar.gz
examples: Change get to use high level APIpgriffis/updated-examples
-rw-r--r--examples/get.c32
1 files 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;
}