diff options
author | Andres Gomez <agomez@igalia.com> | 2013-06-27 18:37:25 +0300 |
---|---|---|
committer | Andres Gomez <agomez@igalia.com> | 2013-07-03 10:45:17 +0300 |
commit | 037c1f92678735c24e337ad568463141710d5679 (patch) | |
tree | c682a1cbfab5b29585dc55ae432fc6bf25c23662 /examples | |
parent | e06d243fadb351b63ba6e7734fd1a9b9fccf4d50 (diff) | |
download | libsoup-037c1f92678735c24e337ad568463141710d5679.tar.gz |
[examples] Added SoupLogger to get example
Now, instead of printing the debug information
manually we use SoupLogger for this with the "-d"
flag.
https://bugzilla.gnome.org/show_bug.cgi?id=703231
Diffstat (limited to 'examples')
-rw-r--r-- | examples/get.c | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/examples/get.c b/examples/get.c index 3540b724..a2307bfd 100644 --- a/examples/get.c +++ b/examples/get.c @@ -1,6 +1,7 @@ /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* * Copyright (C) 2001-2003, Ximian, Inc. + * Copyright (C) 2013 Igalia, S.L. */ #include <stdio.h> @@ -26,35 +27,17 @@ get_url (const char *url) name = soup_message_get_uri (msg)->path; - if (debug || head) { - SoupMessageHeadersIter iter; - const char *hname, *value; - char *path = soup_uri_to_string (soup_message_get_uri (msg), TRUE); - - g_print ("%s %s HTTP/1.%d\n", msg->method, path, - soup_message_get_http_version (msg)); - soup_message_headers_iter_init (&iter, msg->request_headers); - while (soup_message_headers_iter_next (&iter, &hname, &value)) - g_print ("%s: %s\r\n", hname, value); - g_print ("\n"); - - g_print ("HTTP/1.%d %d %s\n", - soup_message_get_http_version (msg), - msg->status_code, msg->reason_phrase); - - soup_message_headers_iter_init (&iter, msg->response_headers); - while (soup_message_headers_iter_next (&iter, &hname, &value)) - g_print ("%s: %s\r\n", hname, value); - g_print ("\n"); - } else if (msg->status_code == SOUP_STATUS_SSL_FAILED) { - GTlsCertificateFlags flags; - - if (soup_message_get_https_status (msg, NULL, &flags)) - g_print ("%s: %d %s (0x%x)\n", name, msg->status_code, msg->reason_phrase, flags); - else - g_print ("%s: %d %s (no handshake status)\n", name, msg->status_code, msg->reason_phrase); - } else if (!quiet || SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code)) - g_print ("%s: %d %s\n", name, msg->status_code, msg->reason_phrase); + if (!debug) { + if (msg->status_code == SOUP_STATUS_SSL_FAILED) { + GTlsCertificateFlags flags; + + if (soup_message_get_https_status (msg, NULL, &flags)) + g_print ("%s: %d %s (0x%x)\n", name, msg->status_code, msg->reason_phrase, flags); + else + g_print ("%s: %d %s (no handshake status)\n", name, msg->status_code, msg->reason_phrase); + } else if (!quiet || SOUP_STATUS_IS_TRANSPORT_ERROR (msg->status_code)) + g_print ("%s: %d %s\n", name, msg->status_code, msg->reason_phrase); + } if (SOUP_STATUS_IS_REDIRECTION (msg->status_code)) { header = soup_message_headers_get_one (msg->response_headers, @@ -113,6 +96,7 @@ main (int argc, char **argv) const char *url; SoupURI *proxy_uri, *parsed; GError *error = NULL; + SoupLogger *logger = NULL; opts = g_option_context_new (NULL); g_option_context_add_main_entries (opts, entries, NULL); @@ -148,6 +132,12 @@ main (int argc, char **argv) SOUP_SESSION_USE_NTLM, ntlm, NULL); + if (debug) { + logger = soup_logger_new (SOUP_LOGGER_LOG_BODY, -1); + soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger)); + g_object_unref (logger); + } + if (proxy) { proxy_uri = soup_uri_new (proxy); if (!proxy_uri) { |