Commit a3577635 authored by Carlos Garcia Campos's avatar Carlos Garcia Campos Committed by Carlos Garcia Campos

soup-session: soup_session_has_feature doesn't work for requests

We are currently using the hash table value as a key in the lookup. So,
we compare the feature type with the registewred schemes. We should get
the list of schemes and find one in the table whose value matches the
given type.
parent ab859a8a
Pipeline #193697 passed with stage
in 1 minute and 5 seconds
...@@ -2878,8 +2878,21 @@ soup_session_has_feature (SoupSession *session, ...@@ -2878,8 +2878,21 @@ soup_session_has_feature (SoupSession *session,
return TRUE; return TRUE;
} }
} else if (g_type_is_a (feature_type, SOUP_TYPE_REQUEST)) { } else if (g_type_is_a (feature_type, SOUP_TYPE_REQUEST)) {
return g_hash_table_lookup (priv->request_types, SoupRequestClass *request_class;
GSIZE_TO_POINTER (feature_type)) != NULL; int i;
request_class = g_type_class_peek (feature_type);
if (!request_class)
return FALSE;
for (i = 0; request_class->schemes[i]; i++) {
gpointer type;
type = g_hash_table_lookup (priv->request_types,
if (type && g_type_is_a (GPOINTER_TO_SIZE (type), feature_type))
return TRUE;
} else { } else {
for (f = priv->features; f; f = f->next) { for (f = priv->features; f; f = f->next) {
if (soup_session_feature_has_feature (f->data, feature_type)) if (soup_session_feature_has_feature (f->data, feature_type))
...@@ -370,6 +370,46 @@ do_property_tests (void) ...@@ -370,6 +370,46 @@ do_property_tests (void)
g_object_unref (session); g_object_unref (session);
} }
static gint
compare_by_gtype (gconstpointer a,
gconstpointer b)
static void
do_features_test (void)
SoupSession *session;
GSList *features;
SoupSessionFeature *feature;
session = soup_test_session_new (SOUP_TYPE_SESSION_ASYNC, NULL);
features = soup_session_get_features (session, SOUP_TYPE_SESSION_FEATURE);
/* SoupAuthManager is always added */
g_assert_cmpuint (g_slist_length (features), >=, 1);
g_assert_nonnull (g_slist_find_custom (features, GSIZE_TO_POINTER (SOUP_TYPE_AUTH_MANAGER), compare_by_gtype));
g_assert_true (soup_session_has_feature (session, SOUP_TYPE_AUTH_MANAGER));
feature = soup_session_get_feature (session, SOUP_TYPE_AUTH_MANAGER);
g_assert_true (SOUP_IS_AUTH_MANAGER (feature));
soup_session_remove_feature (session, feature);
g_assert_false (soup_session_has_feature (session, SOUP_TYPE_AUTH_MANAGER));
g_assert_null (soup_session_get_feature (session, SOUP_TYPE_AUTH_MANAGER));
g_slist_free (features);
/* HTTP, File and Data requests are always added */
g_assert_true (soup_session_has_feature (session, SOUP_TYPE_REQUEST_HTTP));
g_assert_true (soup_session_has_feature (session, SOUP_TYPE_REQUEST_FILE));
g_assert_true (soup_session_has_feature (session, SOUP_TYPE_REQUEST_DATA));
soup_session_remove_feature_by_type (session, SOUP_TYPE_REQUEST_FILE);
g_assert_false (soup_session_has_feature (session, SOUP_TYPE_REQUEST_FILE));
g_assert_true (soup_session_has_feature (session, SOUP_TYPE_REQUEST_HTTP));
g_assert_true (soup_session_has_feature (session, SOUP_TYPE_REQUEST_DATA));
soup_test_session_abort_unref (session);
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
...@@ -388,6 +428,7 @@ main (int argc, char **argv) ...@@ -388,6 +428,7 @@ main (int argc, char **argv)
g_test_add_data_func ("/session/SoupSessionSync", uri, do_sync_tests); g_test_add_data_func ("/session/SoupSessionSync", uri, do_sync_tests);
g_test_add_data_func ("/session/priority", uri, do_priority_tests); g_test_add_data_func ("/session/priority", uri, do_priority_tests);
g_test_add_func ("/session/property", do_property_tests); g_test_add_func ("/session/property", do_property_tests);
g_test_add_func ("/session/features", do_features_test);
ret = g_test_run (); ret = g_test_run ();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment