[libsoup/carlosgc/thread-safe: 9/19] message: make it possible to force http/2 too
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/carlosgc/thread-safe: 9/19] message: make it possible to force http/2 too
- Date: Wed, 20 Apr 2022 13:08:12 +0000 (UTC)
commit ab52e91333ede595fb4a11993f321ee5f272fe0c
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Wed Apr 13 10:19:51 2022 +0200
message: make it possible to force http/2 too
Now that apache supports http/2 for tests, we need a way to force http/2
because http1 is still the preferred protocol. This changes the API to
force http1 into force http version. It's not exactly the same because
force http1 also included http 1.0, but forcing http 1.1 should just
work too.
libsoup/soup-connection-manager.c | 10 ++++-----
libsoup/soup-connection.c | 45 +++++++++++++++++++++++++--------------
libsoup/soup-message-private.h | 6 +++---
libsoup/soup-message.c | 15 +++++++------
libsoup/soup-session.c | 2 +-
5 files changed, 46 insertions(+), 32 deletions(-)
---
diff --git a/libsoup/soup-connection-manager.c b/libsoup/soup-connection-manager.c
index fda98de2..0feeb398 100644
--- a/libsoup/soup-connection-manager.c
+++ b/libsoup/soup-connection-manager.c
@@ -361,7 +361,7 @@ soup_connection_manager_get_connection_locked (SoupConnectionManager *manager,
SoupConnection *conn;
SoupSocketProperties *socket_props;
SoupHost *host;
- gboolean force_http1;
+ guint8 force_http_version;
GList *l;
GSocketConnectable *remote_connectable;
gboolean try_cleanup = TRUE;
@@ -374,7 +374,7 @@ soup_connection_manager_get_connection_locked (SoupConnectionManager *manager,
host = soup_connection_manager_get_host_for_message (manager, msg);
- force_http1 = g_getenv ("SOUP_FORCE_HTTP1") ? TRUE : soup_message_get_force_http1 (msg);
+ force_http_version = g_getenv ("SOUP_FORCE_HTTP1") ? SOUP_HTTP_1_1 :
soup_message_get_force_http_version (msg);
while (TRUE) {
for (l = host->conns; l && l->data; l = g_list_next (l)) {
SoupHTTPVersion http_version;
@@ -382,7 +382,7 @@ soup_connection_manager_get_connection_locked (SoupConnectionManager *manager,
conn = (SoupConnection *)l->data;
http_version = soup_connection_get_negotiated_protocol (conn);
- if (force_http1 && http_version > SOUP_HTTP_1_1)
+ if (force_http_version <= SOUP_HTTP_1_1 && http_version > SOUP_HTTP_1_1)
continue;
switch (soup_connection_get_state (conn)) {
@@ -401,7 +401,7 @@ soup_connection_manager_get_connection_locked (SoupConnectionManager *manager,
/* Always wait if we have a pending connection as it may be
* an h2 connection which will be shared. http/1.x connections
* will only be slightly delayed. */
- if (!force_http1 && !need_new_connection && !item->connect_only &&
item->async)
+ if (force_http_version > SOUP_HTTP_1_1 && !need_new_connection &&
!item->connect_only && item->async)
return NULL;
default:
break;
@@ -465,7 +465,7 @@ soup_connection_manager_get_connection_locked (SoupConnectionManager *manager,
"remote-connectable", remote_connectable,
"ssl", soup_uri_is_https (host->uri),
"socket-properties", socket_props,
- "force-http1", force_http1,
+ "force-http-version", force_http_version,
NULL);
g_signal_connect (conn, "disconnected",
diff --git a/libsoup/soup-connection.c b/libsoup/soup-connection.c
index 80138544..0c9788b9 100644
--- a/libsoup/soup-connection.c
+++ b/libsoup/soup-connection.c
@@ -31,7 +31,7 @@ typedef struct {
SoupSocketProperties *socket_props;
guint64 id;
GSocketAddress *remote_address;
- gboolean force_http1;
+ guint8 force_http_version;
GUri *proxy_uri;
gboolean ssl;
@@ -75,7 +75,7 @@ enum {
PROP_TLS_CERTIFICATE_ERRORS,
PROP_TLS_PROTOCOL_VERSION,
PROP_TLS_CIPHERSUITE_NAME,
- PROP_FORCE_HTTP1,
+ PROP_FORCE_HTTP_VERSION,
LAST_PROPERTY
};
@@ -95,6 +95,7 @@ soup_connection_init (SoupConnection *conn)
SoupConnectionPrivate *priv = soup_connection_get_instance_private (conn);
priv->http_version = SOUP_HTTP_1_1;
+ priv->force_http_version = G_MAXUINT8;
}
static void
@@ -156,8 +157,8 @@ soup_connection_set_property (GObject *object, guint prop_id,
case PROP_ID:
priv->id = g_value_get_uint64 (value);
break;
- case PROP_FORCE_HTTP1:
- priv->force_http1 = g_value_get_boolean (value);
+ case PROP_FORCE_HTTP_VERSION:
+ priv->force_http_version = g_value_get_uchar (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -202,8 +203,8 @@ soup_connection_get_property (GObject *object, guint prop_id,
case PROP_TLS_CIPHERSUITE_NAME:
g_value_set_string (value, soup_connection_get_tls_ciphersuite_name (SOUP_CONNECTION
(object)));
break;
- case PROP_FORCE_HTTP1:
- g_value_set_boolean (value, priv->force_http1);
+ case PROP_FORCE_HTTP_VERSION:
+ g_value_set_uchar (value, priv->force_http_version);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -344,12 +345,13 @@ soup_connection_class_init (SoupConnectionClass *connection_class)
NULL,
G_PARAM_READABLE |
G_PARAM_STATIC_STRINGS);
- properties[PROP_FORCE_HTTP1] =
- g_param_spec_boolean ("force-http1",
- "Force HTTP 1.x",
- "Force connection to use HTTP 1.x",
- FALSE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS);
+ properties[PROP_FORCE_HTTP_VERSION] =
+ g_param_spec_uchar ("force-http-version",
+ "Force HTTP version",
+ "Force connection to use a specific HTTP version",
+ 0, G_MAXUINT8, G_MAXUINT8,
+ G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, LAST_PROPERTY, properties);
}
@@ -568,11 +570,22 @@ new_tls_connection (SoupConnection *conn,
GPtrArray *advertised_protocols = g_ptr_array_sized_new (4);
// https://www.iana.org/assignments/tls-extensiontype-values/tls-extensiontype-values.xhtml
- if (!priv->force_http1)
+ switch (priv->force_http_version) {
+ case SOUP_HTTP_1_0:
+ g_ptr_array_add (advertised_protocols, "http/1.0");
+ break;
+ case SOUP_HTTP_1_1:
+ g_ptr_array_add (advertised_protocols, "http/1.1");
+ break;
+ case SOUP_HTTP_2_0:
g_ptr_array_add (advertised_protocols, "h2");
-
- g_ptr_array_add (advertised_protocols, "http/1.1");
- g_ptr_array_add (advertised_protocols, "http/1.0");
+ break;
+ default:
+ g_ptr_array_add (advertised_protocols, "h2");
+ g_ptr_array_add (advertised_protocols, "http/1.1");
+ g_ptr_array_add (advertised_protocols, "http/1.0");
+ break;
+ }
g_ptr_array_add (advertised_protocols, NULL);
tls_interaction = priv->socket_props->tls_interaction ? g_object_ref
(priv->socket_props->tls_interaction) : soup_tls_interaction_new (conn);
diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h
index 8b3ad56f..c036630e 100644
--- a/libsoup/soup-message-private.h
+++ b/libsoup/soup-message-private.h
@@ -147,10 +147,10 @@ void soup_message_update_request_host_if_needed (SoupMessage *msg);
void soup_message_force_keep_alive_if_needed (SoupMessage *msg);
-void soup_message_set_force_http1 (SoupMessage *msg,
- gboolean force_http1);
+void soup_message_set_force_http_version (SoupMessage *msg,
+ guint8 version);
-gboolean soup_message_get_force_http1 (SoupMessage *msg);
+guint8 soup_message_get_force_http_version (SoupMessage *msg);
void soup_message_set_is_misdirected_retry (SoupMessage *msg,
gboolean is_misdirected_retry);
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index ad408b11..e38d562e 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -94,9 +94,9 @@ typedef struct {
gboolean is_top_level_navigation;
gboolean is_options_ping;
gboolean is_preconnect;
- gboolean force_http1;
gboolean is_misdirected_retry;
guint last_connection_id;
+ guint8 force_http_version;
GSocketAddress *remote_address;
SoupMessageMetrics *metrics;
@@ -164,6 +164,7 @@ soup_message_init (SoupMessage *msg)
priv->http_version = priv->orig_http_version = SOUP_HTTP_1_1;
priv->priority = SOUP_MESSAGE_PRIORITY_NORMAL;
+ priv->force_http_version = G_MAXUINT8;
priv->request_headers = soup_message_headers_new (SOUP_MESSAGE_HEADERS_REQUEST);
priv->response_headers = soup_message_headers_new (SOUP_MESSAGE_HEADERS_RESPONSE);
@@ -3219,20 +3220,20 @@ soup_message_force_keep_alive_if_needed (SoupMessage *msg)
}
void
-soup_message_set_force_http1 (SoupMessage *msg,
- gboolean force_http1)
+soup_message_set_force_http_version (SoupMessage *msg,
+ guint8 version)
{
SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
- priv->force_http1 = force_http1;
+ priv->force_http_version = version;
}
-gboolean
-soup_message_get_force_http1 (SoupMessage *msg)
+guint8
+soup_message_get_force_http_version (SoupMessage *msg)
{
SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
- return priv->force_http1;
+ return priv->force_http_version;
}
void
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 0a27ba3b..387f71f3 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -3577,7 +3577,7 @@ soup_session_websocket_connect_async (SoupSession *session,
/* WebSocket negotiation over HTTP/2 is not currently supported
* and in practice all websocket servers support HTTP1.x with
* HTTP/2 not providing a tangible benefit */
- soup_message_set_force_http1 (msg, TRUE);
+ soup_message_set_force_http_version (msg, SOUP_HTTP_1_1);
item = soup_session_append_queue_item (session, msg, TRUE, cancellable);
item->io_priority = io_priority;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]