[libsoup] logger: do not log preconnect messages
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] logger: do not log preconnect messages
- Date: Mon, 14 Jun 2021 10:55:30 +0000 (UTC)
commit 7436035f89eda7fd5ffa41b810bc0d23a9368499
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Mon Jun 14 12:54:19 2021 +0200
logger: do not log preconnect messages
libsoup/soup-logger.c | 6 ++++++
tests/logger-test.c | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 45 insertions(+)
---
diff --git a/libsoup/soup-logger.c b/libsoup/soup-logger.c
index e3963c52..933b7b73 100644
--- a/libsoup/soup-logger.c
+++ b/libsoup/soup-logger.c
@@ -773,6 +773,12 @@ finished (SoupMessage *msg, gpointer user_data)
{
SoupLogger *logger = user_data;
+ /* Do not print the response if we didn't print a request. This can happen if
+ * msg is a preconnect request, for example.
+ */
+ if (!soup_logger_get_id (logger, msg))
+ return;
+
print_response (logger, msg);
soup_logger_print (logger, SOUP_LOGGER_LOG_MINIMAL, ' ', "\n");
}
diff --git a/tests/logger-test.c b/tests/logger-test.c
index 19145b21..b5d2f27b 100644
--- a/tests/logger-test.c
+++ b/tests/logger-test.c
@@ -425,6 +425,44 @@ do_logger_cookies_test (void)
soup_test_session_abort_unref (session);
}
+static void
+preconnect_message_finsihed_cb (SoupMessage *msg,
+ gboolean *finished)
+{
+ *finished = TRUE;
+}
+
+static void
+do_logger_preconnect_test (void)
+{
+ SoupSession *session;
+ SoupLogger *logger;
+ SoupMessage *msg;
+ gboolean finished = FALSE;
+ LogData log = { NULL, NULL, NULL, NULL };
+
+ /* Preconnect messages should not be logged */
+ session = soup_test_session_new (NULL);
+ logger = soup_logger_new (SOUP_LOGGER_LOG_MINIMAL);
+ soup_logger_set_printer (logger, (SoupLoggerPrinter)printer, &log, NULL);
+ soup_session_add_feature (session, SOUP_SESSION_FEATURE (logger));
+ g_object_unref (logger);
+
+ msg = soup_message_new_from_uri ("HEAD", base_uri);
+ g_signal_connect_after (msg, "finished",
+ G_CALLBACK (preconnect_message_finsihed_cb),
+ &finished);
+ soup_session_preconnect_async (session, msg, G_PRIORITY_DEFAULT, NULL, NULL, NULL);
+ while (!finished)
+ g_main_context_iteration (NULL, TRUE);
+ g_object_unref (msg);
+
+ g_assert_null (log.request);
+ g_assert_null (log.response);
+
+ soup_test_session_abort_unref (session);
+}
+
static void
server_callback (SoupServer *server,
SoupServerMessage *msg,
@@ -460,6 +498,7 @@ main (int argc, char **argv)
g_test_add_func ("/logger/body", do_logger_body_test);
g_test_add_func ("/logger/filters", do_logger_filters_test);
g_test_add_func ("/logger/cookies", do_logger_cookies_test);
+ g_test_add_func ("/logger/preconnect", do_logger_preconnect_test);
ret = g_test_run ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]