summaryrefslogtreecommitdiff
path: root/libsoup
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2022-04-20 12:30:11 +0200
committerCarlos Garcia Campos <cgarcia@igalia.com>2022-06-08 12:36:17 +0200
commit05d07ee44f69cf93d1abb98d88aa7688b4cb6fdb (patch)
treec00164a794a39ffee7d156a1f57d81c72d737e28 /libsoup
parent1bb3af2aa911d36a84483d37e04a63d9d397a6c4 (diff)
downloadlibsoup-05d07ee44f69cf93d1abb98d88aa7688b4cb6fdb.tar.gz
logger: remove soup_logger_request_body_setup()
We can use the same approach as http2 backend and call soup_logger_log_request_data() from the body stream wrote data callback.
Diffstat (limited to 'libsoup')
-rw-r--r--libsoup/http1/soup-client-message-io-http1.c13
-rw-r--r--libsoup/soup-logger-private.h4
-rw-r--r--libsoup/soup-logger.c60
3 files changed, 8 insertions, 69 deletions
diff --git a/libsoup/http1/soup-client-message-io-http1.c b/libsoup/http1/soup-client-message-io-http1.c
index 129ddb4f..1f421d6d 100644
--- a/libsoup/http1/soup-client-message-io-http1.c
+++ b/libsoup/http1/soup-client-message-io-http1.c
@@ -38,6 +38,9 @@ typedef struct {
SoupMessageMetrics *metrics;
+ /* Request body logger */
+ SoupLogger *logger;
+
#ifdef HAVE_SYSPROF
gint64 begin_time_nsec;
#endif
@@ -146,8 +149,11 @@ request_body_stream_wrote_data_cb (SoupMessage *msg,
client_io->msg_io->metrics->request_body_size += count;
}
- if (!is_metadata)
+ if (!is_metadata) {
+ if (client_io->msg_io->logger)
+ soup_logger_log_request_data (client_io->msg_io->logger, msg, (const char *)buffer, count);
soup_message_wrote_body_data (msg, count);
+ }
}
static void
@@ -354,10 +360,7 @@ io_write (SoupClientMessageIOHTTP1 *client_io,
io->write_state = SOUP_MESSAGE_IO_STATE_BODY;
logger = soup_session_get_feature_for_message (client_io->msg_io->item->session,
SOUP_TYPE_LOGGER, msg);
- if (logger) {
- soup_logger_request_body_setup (SOUP_LOGGER (logger), msg,
- SOUP_BODY_OUTPUT_STREAM (io->body_ostream));
- }
+ client_io->msg_io->logger = logger ? SOUP_LOGGER (logger) : NULL;
break;
case SOUP_MESSAGE_IO_STATE_BODY:
diff --git a/libsoup/soup-logger-private.h b/libsoup/soup-logger-private.h
index e48d16c0..c0c16b2e 100644
--- a/libsoup/soup-logger-private.h
+++ b/libsoup/soup-logger-private.h
@@ -9,10 +9,6 @@
G_BEGIN_DECLS
-void soup_logger_request_body_setup (SoupLogger *logger,
- SoupMessage *msg,
- SoupBodyOutputStream *stream);
-
void soup_logger_log_request_data (SoupLogger *logger, SoupMessage *msg, const char *buffer, gsize len);
G_END_DECLS
diff --git a/libsoup/soup-logger.c b/libsoup/soup-logger.c
index af968ff2..f26d7c13 100644
--- a/libsoup/soup-logger.c
+++ b/libsoup/soup-logger.c
@@ -94,7 +94,6 @@ typedef struct {
GMutex mutex;
GHashTable *ids;
GHashTable *request_bodies;
- GHashTable *request_messages;
GHashTable *response_bodies;
SoupSession *session;
@@ -125,8 +124,6 @@ enum {
static GParamSpec *properties[LAST_PROPERTY] = { NULL, };
-static void body_ostream_done (gpointer data, GObject *bostream);
-
static void soup_logger_session_feature_init (SoupSessionFeatureInterface *feature_interface, gpointer interface_data);
static SoupContentProcessorInterface *soup_logger_default_content_processor_interface;
@@ -250,29 +247,18 @@ soup_logger_init (SoupLogger *logger)
priv->ids = g_hash_table_new (NULL, NULL);
priv->request_bodies = g_hash_table_new_full (NULL, NULL, NULL, body_free);
priv->response_bodies = g_hash_table_new_full (NULL, NULL, NULL, body_free);
- priv->request_messages = g_hash_table_new (NULL, NULL);
g_mutex_init (&priv->mutex);
}
static void
-body_ostream_drop_ref (gpointer key, gpointer value, gpointer data)
-{
- g_object_weak_unref (key, body_ostream_done, data);
-}
-
-static void
soup_logger_finalize (GObject *object)
{
SoupLogger *logger = SOUP_LOGGER (object);
SoupLoggerPrivate *priv = soup_logger_get_instance_private (logger);
- g_hash_table_foreach (priv->request_messages,
- body_ostream_drop_ref, priv);
-
g_hash_table_destroy (priv->ids);
g_hash_table_destroy (priv->request_bodies);
g_hash_table_destroy (priv->response_bodies);
- g_hash_table_destroy (priv->request_messages);
if (priv->request_filter_dnotify)
priv->request_filter_dnotify (priv->request_filter_data);
@@ -846,52 +832,6 @@ got_body (SoupMessage *msg, gpointer user_data)
}
static void
-body_stream_wrote_data_cb (GOutputStream *stream,
- const void *buffer,
- guint count,
- gboolean is_metadata,
- SoupLogger *logger)
-{
- SoupLoggerPrivate *priv;
- SoupMessage *msg;
-
- if (is_metadata)
- return;
-
- priv = soup_logger_get_instance_private (logger);
- g_mutex_lock (&priv->mutex);
- msg = g_hash_table_lookup (priv->request_messages, stream);
- g_mutex_unlock (&priv->mutex);
- write_body (logger, buffer, count, msg, priv->request_bodies);
-}
-
-static void
-body_ostream_done (gpointer data, GObject *bostream)
-{
- SoupLoggerPrivate *priv = data;
-
- g_mutex_lock (&priv->mutex);
- g_hash_table_remove (priv->request_messages, bostream);
- g_mutex_unlock (&priv->mutex);
-}
-
-void
-soup_logger_request_body_setup (SoupLogger *logger,
- SoupMessage *msg,
- SoupBodyOutputStream *stream)
-{
- SoupLoggerPrivate *priv = soup_logger_get_instance_private (logger);
-
- g_mutex_lock (&priv->mutex);
- g_hash_table_insert (priv->request_messages, stream, msg);
- g_mutex_unlock (&priv->mutex);
- g_signal_connect_object (stream, "wrote-data",
- G_CALLBACK (body_stream_wrote_data_cb),
- logger, 0);
- g_object_weak_ref (G_OBJECT (stream), body_ostream_done, priv);
-}
-
-static void
wrote_body (SoupMessage *msg, gpointer user_data)
{
SoupLogger *logger = SOUP_LOGGER (user_data);