[libsoup] message: add soup_message_force_keep_alive_if_needed()
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] message: add soup_message_force_keep_alive_if_needed()
- Date: Sun, 9 May 2021 10:49:56 +0000 (UTC)
commit 917edfa2f0721dd4ef43953d636c0be68912021c
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Sun May 9 12:48:25 2021 +0200
message: add soup_message_force_keep_alive_if_needed()
libsoup/soup-message-private.h | 2 ++
libsoup/soup-message.c | 23 +++++++++++++++++++++++
libsoup/soup-session.c | 12 +-----------
3 files changed, 26 insertions(+), 11 deletions(-)
---
diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h
index 5942ee67..71da0aaa 100644
--- a/libsoup/soup-message-private.h
+++ b/libsoup/soup-message-private.h
@@ -144,4 +144,6 @@ void soup_message_set_request_host_from_uri (SoupMessage *msg,
void soup_message_update_request_host_if_needed (SoupMessage *msg);
+void soup_message_force_keep_alive_if_needed (SoupMessage *msg);
+
#endif /* __SOUP_MESSAGE_PRIVATE_H__ */
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index b5f2e346..ef4d782a 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -1665,6 +1665,9 @@ soup_message_is_keepalive (SoupMessage *msg)
{
SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
+ if (priv->http_version == SOUP_HTTP_2_0)
+ return FALSE;
+
if (priv->status_code == SOUP_STATUS_OK &&
priv->method == SOUP_METHOD_CONNECT)
return TRUE;
@@ -2659,3 +2662,23 @@ soup_message_update_request_host_if_needed (SoupMessage *msg)
soup_message_set_request_host_from_uri (msg, priv->uri);
}
+
+void
+soup_message_force_keep_alive_if_needed (SoupMessage *msg)
+{
+ SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
+
+ if (priv->http_version == SOUP_HTTP_2_0)
+ return;
+
+ /* Force keep alive connections for HTTP 1.0. Performance will
+ * improve when issuing multiple requests to the same host in
+ * a short period of time, as we wouldn't need to establish
+ * new connections. Keep alive is implicit for HTTP 1.1.
+ */
+ if (!soup_message_headers_header_contains (priv->request_headers, "Connection", "Keep-Alive") &&
+ !soup_message_headers_header_contains (priv->request_headers, "Connection", "close") &&
+ !soup_message_headers_header_contains (priv->request_headers, "Connection", "Upgrade")) {
+ soup_message_headers_append (priv->request_headers, "Connection", "Keep-Alive");
+ }
+}
diff --git a/libsoup/soup-session.c b/libsoup/soup-session.c
index 9530730d..b027a19b 100644
--- a/libsoup/soup-session.c
+++ b/libsoup/soup-session.c
@@ -1369,17 +1369,7 @@ soup_session_send_queue_item (SoupSession *session,
if (priv->accept_language && !soup_message_headers_get_list (request_headers, "Accept-Language"))
soup_message_headers_append (request_headers, "Accept-Language", priv->accept_language);
- /* Force keep alive connections for HTTP 1.0. Performance will
- * improve when issuing multiple requests to the same host in
- * a short period of time, as we wouldn't need to establish
- * new connections. Keep alive is implicit for HTTP 1.1.
- */
- if (!soup_message_headers_header_contains (request_headers, "Connection", "Keep-Alive") &&
- !soup_message_headers_header_contains (request_headers, "Connection", "close") &&
- !soup_message_headers_header_contains (request_headers, "Connection", "Upgrade")) {
- soup_message_headers_append (request_headers, "Connection", "Keep-Alive");
- }
-
+ soup_message_force_keep_alive_if_needed (item->msg);
soup_message_update_request_host_if_needed (item->msg);
/* A user agent SHOULD send a Content-Length in a request message when
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]