[libsoup/pgriffis/duplicate-soup-features] session: Forbid multiple features of the same type to be added
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/pgriffis/duplicate-soup-features] session: Forbid multiple features of the same type to be added
- Date: Tue, 25 May 2021 17:03:01 +0000 (UTC)
commit 005f40ac52b979e8033baa2692cc12c21d5b6ce3
Author: Patrick Griffis <pgriffis igalia com>
Date: Tue May 25 09:50:02 2021 -0500
session: Forbid multiple features of the same type to be added
This can cause accidental conflicts and doesn't seem to be valuable
with the current features.
docs/reference/libsoup-3.0-sections.txt | 1 -
libsoup/Soup-3.0.metadata | 1 -
libsoup/soup-session-private.h | 3 +++
libsoup/soup-session.c | 36 +++++++++++++++++++++++----------
libsoup/soup-session.h | 3 ---
tests/session-test.c | 1 +
6 files changed, 29 insertions(+), 16 deletions(-)
---
diff --git a/docs/reference/libsoup-3.0-sections.txt b/docs/reference/libsoup-3.0-sections.txt
index 50050af0..b34559f4 100644
--- a/docs/reference/libsoup-3.0-sections.txt
+++ b/docs/reference/libsoup-3.0-sections.txt
@@ -411,7 +411,6 @@ soup_session_add_feature
soup_session_add_feature_by_type
soup_session_remove_feature
soup_session_remove_feature_by_type
-soup_session_get_features
soup_session_get_feature
soup_session_get_feature_for_message
soup_session_has_feature
diff --git a/libsoup/Soup-3.0.metadata b/libsoup/Soup-3.0.metadata
index 8174e825..1d8bf0d3 100644
--- a/libsoup/Soup-3.0.metadata
+++ b/libsoup/Soup-3.0.metadata
@@ -21,7 +21,6 @@ Message
Server
.new skip=false
Session
- .get_features type_arguments="weak Soup.SessionFeature"
.send_async.cancellable#parameter default=null
Session*.new_with_options skip=false
diff --git a/libsoup/soup-session-private.h b/libsoup/soup-session-private.h
index bef2f888..d27b8955 100644
--- a/libsoup/soup-session-private.h
+++ b/libsoup/soup-session-private.h
@@ -28,6 +28,9 @@ GInputStream *soup_session_setup_message_body_input_stream (SoupSession *
GInputStream *body_stream,
SoupProcessingStage start_at_stage);
+GSList *soup_session_get_features (SoupSession *session,
+ GType feature_type);
+
G_END_DECLS
#endif /* __SOUP_SESSION_PRIVATE_H__ */
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 68d7a026..f1b67e8b 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -2211,12 +2211,25 @@ soup_session_abort (SoupSession *session)
g_slist_free (conns);
}
+static gboolean
+feature_already_added (SoupSession *session, GType feature_type)
+{
+ if (soup_session_has_feature (session, feature_type)) {
+ g_warning ("SoupSession already has a %s, ignoring new feature",
+ g_type_name (feature_type));
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/**
* soup_session_add_feature:
* @session: a #SoupSession
* @feature: an object that implements #SoupSessionFeature
*
- * Adds @feature's functionality to @session.
+ * Adds @feature's functionality to @session. You cannot add multiple
+ * features of the same #GType to a session.
*
* See the main #SoupSession documentation for information on what
* features are present in sessions by default.
@@ -2231,6 +2244,10 @@ soup_session_add_feature (SoupSession *session, SoupSessionFeature *feature)
g_return_if_fail (SOUP_IS_SESSION_FEATURE (feature));
priv = soup_session_get_instance_private (session);
+
+ if (feature_already_added (session, G_TYPE_FROM_INSTANCE (feature)))
+ return;
+
priv->features = g_slist_prepend (priv->features, g_object_ref (feature));
g_hash_table_remove_all (priv->features_cache);
soup_session_feature_attach (feature, session);
@@ -2245,6 +2262,7 @@ soup_session_add_feature (SoupSession *session, SoupSessionFeature *feature)
* #SoupSessionFeature, this creates a new feature of that type and
* adds it to @session as with soup_session_add_feature(). You can use
* this when you don't need to customize the new feature in any way.
+ * Adding multiple features of the same @feature_type is not allowed.
*
* If @feature_type is not a #SoupSessionFeature type, this gives each
* existing feature on @session the chance to accept @feature_type as
@@ -2266,6 +2284,9 @@ soup_session_add_feature_by_type (SoupSession *session, GType feature_type)
if (g_type_is_a (feature_type, SOUP_TYPE_SESSION_FEATURE)) {
SoupSessionFeature *feature;
+ if (feature_already_added (session, feature_type))
+ return;
+
feature = g_object_new (feature_type, NULL);
soup_session_add_feature (session, feature);
g_object_unref (feature);
@@ -2414,9 +2435,7 @@ soup_session_get_features (SoupSession *session, GType feature_type)
* @session: a #SoupSession
* @feature_type: the #GType of the feature to get
*
- * Gets the first feature in @session of type @feature_type. For
- * features where there may be more than one feature of a given type,
- * use soup_session_get_features().
+ * Gets the feature in @session of type @feature_type.
*
* Returns: (nullable) (transfer none): a #SoupSessionFeature, or
* %NULL. The feature is owned by @session.
@@ -2456,13 +2475,8 @@ soup_session_get_feature (SoupSession *session, GType feature_type)
* @feature_type: the #GType of the feature to get
* @msg: a #SoupMessage
*
- * Gets the first feature in @session of type @feature_type, provided
- * that it is not disabled for @msg. As with
- * soup_session_get_feature(), this should only be used for features
- * where @feature_type is only expected to match a single feature. In
- * particular, if there are two matching features, and the first is
- * disabled on @msg, and the second is not, then this will return
- * %NULL, not the second feature.
+ * Gets the feature in @session of type @feature_type, provided
+ * that it is not disabled for @msg.
*
* Returns: (nullable) (transfer none): a #SoupSessionFeature, or %NULL. The
* feature is owned by @session.
diff --git a/libsoup/soup-session.h b/libsoup/soup-session.h
index 61f07b66..624f580a 100644
--- a/libsoup/soup-session.h
+++ b/libsoup/soup-session.h
@@ -161,9 +161,6 @@ SOUP_AVAILABLE_IN_ALL
gboolean soup_session_has_feature (SoupSession *session,
GType feature_type);
SOUP_AVAILABLE_IN_ALL
-GSList *soup_session_get_features (SoupSession *session,
- GType feature_type);
-SOUP_AVAILABLE_IN_ALL
SoupSessionFeature *soup_session_get_feature (SoupSession *session,
GType feature_type);
SOUP_AVAILABLE_IN_ALL
diff --git a/tests/session-test.c b/tests/session-test.c
index 9a4974e0..4a1596b3 100644
--- a/tests/session-test.c
+++ b/tests/session-test.c
@@ -1,6 +1,7 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */
#include "test-utils.h"
+#include "soup-session-private.h"
static GUri *base_uri;
static gboolean server_processed_message;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]