summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Gomez <agomez@igalia.com>2013-07-03 13:06:37 +0300
committerAndres Gomez <agomez@igalia.com>2013-07-15 13:35:49 +0200
commit47615947cf5b135c00f39ce919ef7da9067c2cb0 (patch)
tree62f57914af7cba837378227ec91eb2a392138ae5
parent2e436f5c75fcff49518a33eee6429a23f556ec6d (diff)
downloadlibsoup-47615947cf5b135c00f39ce919ef7da9067c2cb0.tar.gz
[soup-logger] On response, always print headers
SoupLogger won't print any information upon response until the "got-body" or "got-informational" signals are received. If the response message has been cancelled or requeued first, we miss the headers information, even when we would have been already able to print it. Now, upon response, if the logging has not yet happened when the "finished" signal is triggered, we do perform the logging then. https://bugzilla.gnome.org/show_bug.cgi?id=703200
-rw-r--r--libsoup/soup-logger.c43
1 files changed, 36 insertions, 7 deletions
diff --git a/libsoup/soup-logger.c b/libsoup/soup-logger.c
index 52d74cda..a441f211 100644
--- a/libsoup/soup-logger.c
+++ b/libsoup/soup-logger.c
@@ -4,6 +4,7 @@
*
* Copyright (C) 2001-2004 Novell, Inc.
* Copyright (C) 2008 Red Hat, Inc.
+ * Copyright (C) 2013 Igalia, S.L.
*/
#ifdef HAVE_CONFIG_H
@@ -68,13 +69,21 @@
* the first byte of the request gets written to the network (from the
* #SoupSession::request_started signal), which means that if you have
* not made the complete request body available at that point, it will
- * not be logged. The response is logged just after the last byte of
- * the response body is read from the network (from the
- * #SoupMessage::got_body or #SoupMessage::got_informational signal),
- * which means that the #SoupMessage::got_headers signal, and anything
- * triggered off it (such as #SoupSession::authenticate) will be
- * emitted <emphasis>before</emphasis> the response headers are
- * actually logged.
+ * not be logged.
+ *
+ * The response is logged just after the last byte of the response
+ * body is read from the network (from the #SoupMessage::got_body or
+ * #SoupMessage::got_informational signal), which means that the
+ * #SoupMessage::got_headers signal, and anything triggered off it
+ * (such as #SoupSession::authenticate) will be emitted
+ * <emphasis>before</emphasis> the response headers are actually
+ * logged.
+ *
+ * If the response doesn't happen to trigger the
+ * #SoupMessage::got_body nor #SoupMessage::got_informational signals
+ * due to, for example, a cancellation before receiving the last byte
+ * of the response body, the response will still be logged on the
+ * event of the #SoupMessage::finished signal.
**/
static void soup_logger_session_feature_init (SoupSessionFeatureInterface *feature_interface, gpointer interface_data);
@@ -574,6 +583,20 @@ print_response (SoupLogger *logger, SoupMessage *msg)
}
static void
+finished (SoupMessage *msg, gpointer user_data)
+{
+ SoupLogger *logger = user_data;
+ SoupLoggerPrivate *priv = SOUP_LOGGER_GET_PRIVATE (logger);
+
+ g_mutex_lock (&priv->lock);
+
+ print_response (logger, msg);
+ soup_logger_print (logger, SOUP_LOGGER_LOG_MINIMAL, ' ', "");
+
+ g_mutex_unlock (&priv->lock);
+}
+
+static void
got_informational (SoupMessage *msg, gpointer user_data)
{
SoupLogger *logger = user_data;
@@ -581,6 +604,7 @@ got_informational (SoupMessage *msg, gpointer user_data)
g_mutex_lock (&priv->lock);
+ g_signal_handlers_disconnect_by_func (msg, finished, logger);
print_response (logger, msg);
soup_logger_print (logger, SOUP_LOGGER_LOG_MINIMAL, ' ', "");
@@ -615,6 +639,7 @@ got_body (SoupMessage *msg, gpointer user_data)
g_mutex_lock (&priv->lock);
+ g_signal_handlers_disconnect_by_func (msg, finished, logger);
print_response (logger, msg);
soup_logger_print (logger, SOUP_LOGGER_LOG_MINIMAL, ' ', "");
@@ -634,6 +659,9 @@ soup_logger_request_queued (SoupSessionFeature *logger,
g_signal_connect (msg, "got-body",
G_CALLBACK (got_body),
logger);
+ g_signal_connect (msg, "finished",
+ G_CALLBACK (finished),
+ logger);
}
static void
@@ -677,6 +705,7 @@ soup_logger_request_unqueued (SoupSessionFeature *logger,
g_signal_handlers_disconnect_by_func (msg, got_informational, logger);
g_signal_handlers_disconnect_by_func (msg, got_body, logger);
+ g_signal_handlers_disconnect_by_func (msg, finished, logger);
}
static void