From 767c61f390840ba5c2c17a7fb3e49551816ceded Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Wed, 7 Dec 2022 14:16:28 +0100 Subject: soup-connection-manager: Read 'SOUP_FORCE_HTTP1' environment variable only once The environment variables usually do not change during runtime, it's unexpected even for this semi-debugging variable, thus let it be read only once and the result being used repeatedly. --- libsoup/soup-connection-manager.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libsoup/soup-connection-manager.c b/libsoup/soup-connection-manager.c index d0082981..981a3d30 100644 --- a/libsoup/soup-connection-manager.c +++ b/libsoup/soup-connection-manager.c @@ -378,6 +378,7 @@ static SoupConnection * soup_connection_manager_get_connection_locked (SoupConnectionManager *manager, SoupMessageQueueItem *item) { + static gchar env_force_http1 = -1; SoupMessage *msg = item->msg; gboolean need_new_connection; SoupConnection *conn; @@ -388,6 +389,9 @@ soup_connection_manager_get_connection_locked (SoupConnectionManager *manager, GSocketConnectable *remote_connectable; gboolean try_cleanup = TRUE; + if (env_force_http1 == -1) + env_force_http1 = g_getenv ("SOUP_FORCE_HTTP1") != NULL ? 1 : 0; + need_new_connection = (soup_message_query_flags (msg, SOUP_MESSAGE_NEW_CONNECTION)) || (soup_message_is_misdirected_retry (msg)) || @@ -396,7 +400,7 @@ soup_connection_manager_get_connection_locked (SoupConnectionManager *manager, host = soup_connection_manager_get_or_create_host_for_item (manager, item); - force_http_version = g_getenv ("SOUP_FORCE_HTTP1") ? SOUP_HTTP_1_1 : soup_message_get_force_http_version (msg); + force_http_version = env_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; -- cgit v1.2.1