summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Garcia Campos <cgarcia@igalia.com>2022-05-03 11:58:13 +0200
committerCarlos Garcia Campos <cgarcia@igalia.com>2022-05-03 11:59:44 +0200
commitbe49da5da414e1f97c932ee6dd94392e3fffab29 (patch)
treeff1a0df0fdf86611fa8d5e621693e16baa2065e5
parent5a57bdee5078b94ccecdb00b0b88204c9c7a6585 (diff)
downloadlibsoup-be49da5da414e1f97c932ee6dd94392e3fffab29.tar.gz
Make sure we don't reuse a http/1 idle connection when http/2 is forced
-rw-r--r--libsoup/soup-session.c2
-rw-r--r--tests/connection-test.c55
2 files changed, 56 insertions, 1 deletions
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index a698f28e..dc6c992b 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -1837,7 +1837,7 @@ get_connection_for_host (SoupSession *session,
conn = conns->data;
http_version = soup_connection_get_negotiated_protocol (conn);
- if (force_http_version <= SOUP_HTTP_1_1 && http_version > SOUP_HTTP_1_1)
+ if (force_http_version <= SOUP_HTTP_2_0 && http_version != force_http_version)
continue;
switch (soup_connection_get_state (conn)) {
diff --git a/tests/connection-test.c b/tests/connection-test.c
index 2e90cce1..3ee74b60 100644
--- a/tests/connection-test.c
+++ b/tests/connection-test.c
@@ -1591,6 +1591,60 @@ do_connection_metrics_test (void)
soup_test_session_abort_unref (session);
}
+static void
+force_http2_test_network_event (SoupMessage *msg,
+ GSocketClientEvent event,
+ GIOStream *connection,
+ SoupConnection **conn)
+{
+ if (event != G_SOCKET_CLIENT_RESOLVING)
+ return;
+
+ *conn = soup_message_get_connection (msg);
+}
+
+static void
+do_connection_force_http2_test (void)
+{
+ SoupSession *session;
+ SoupMessage *msg;
+ SoupConnection *conn1 = NULL;
+ SoupConnection *conn2 = NULL;
+ GBytes *body;
+
+ SOUP_TEST_SKIP_IF_NO_TLS;
+ SOUP_TEST_SKIP_IF_NO_APACHE;
+
+ session = soup_test_session_new (NULL);
+
+ msg = soup_message_new ("GET", HTTPS_SERVER);
+ g_signal_connect (msg, "network-event",
+ G_CALLBACK (force_http2_test_network_event),
+ &conn1);
+ body = soup_session_send_and_read (session, msg, NULL, NULL);
+ g_assert_nonnull (conn1);
+ g_assert_cmpint (soup_connection_get_state (conn1), ==, SOUP_CONNECTION_IDLE);
+ g_assert_cmpint (soup_connection_get_negotiated_protocol (conn1), ==, SOUP_HTTP_1_1);
+ g_object_unref (msg);
+ g_bytes_unref (body);
+
+ /* With HTTP/2 forced, a new connection must be created */
+ msg = soup_message_new ("GET", HTTPS_SERVER);
+ g_signal_connect (msg, "network-event",
+ G_CALLBACK (force_http2_test_network_event),
+ &conn2);
+ soup_message_set_force_http_version (msg, SOUP_HTTP_2_0);
+ body = soup_session_send_and_read (session, msg, NULL, NULL);
+ g_assert_nonnull (conn2);
+ g_assert_cmpint (soup_connection_get_state (conn2), ==, SOUP_CONNECTION_IDLE);
+ g_assert_cmpint (soup_connection_get_negotiated_protocol (conn2), ==, SOUP_HTTP_2_0);
+ g_assert_false (conn1 == conn2);
+ g_object_unref (msg);
+ g_bytes_unref (body);
+
+ soup_test_session_abort_unref (session);
+}
+
int
main (int argc, char **argv)
{
@@ -1614,6 +1668,7 @@ main (int argc, char **argv)
g_test_add_func ("/connection/event", do_connection_event_test);
g_test_add_func ("/connection/preconnect", do_connection_preconnect_test);
g_test_add_func ("/connection/metrics", do_connection_metrics_test);
+ g_test_add_func ("/connection/force-http2", do_connection_force_http2_test);
ret = g_test_run ();