soup-session.c: always send the "Keep-Alive" header
authorSergio Villar Senin <svillar@igalia.com>
Tue, 26 Apr 2011 16:47:11 +0000 (18:47 +0200)
committerSergio Villar Senin <svillar@igalia.com>
Tue, 26 Apr 2011 17:18:38 +0000 (19:18 +0200)
This will save us many new connection attempts when connecting to HTTP1.0
servers that automatically try to close the connection unless specified by
the client.

https://bugzilla.gnome.org/show_bug.cgi?id=648680

libsoup/soup-session.c

index ba98e65..0a7f7a3 100644 (file)
@@ -66,8 +66,6 @@ typedef struct {
        guint        num_conns;
 
        guint        num_messages;
-
-       SoupHTTPVersion http_version;
 } SoupSessionHost;
 
 typedef struct {
@@ -1037,7 +1035,6 @@ soup_session_host_new (SoupSession *session, SoupURI *uri)
        host = g_slice_new0 (SoupSessionHost);
        host->uri = soup_uri_copy_host (uri);
        host->addr = soup_address_new (host->uri->host, host->uri->port);
-       host->http_version = SOUP_HTTP_1_1;
 
        return host;
 }
@@ -1190,8 +1187,7 @@ soup_session_send_queue_item (SoupSession *session,
                              SoupMessageCompletionFn completion_cb)
 {
        SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
-       SoupHTTPVersion http_version;
-       SoupSessionHost *host;
+       const char *conn_header;
 
        if (priv->user_agent) {
                soup_message_headers_replace (item->msg->request_headers,
@@ -1206,27 +1202,17 @@ soup_session_send_queue_item (SoupSession *session,
                                             priv->accept_language);
        }
 
-       g_mutex_lock (priv->host_lock);
-       host = get_host_for_message (session, item->msg);
-       http_version = host->http_version;
-       g_mutex_unlock (priv->host_lock);
-
        /* 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 (http_version == SOUP_HTTP_1_0) {
-               const gchar* conn_header;
-
-               conn_header = soup_message_headers_get_list (item->msg->request_headers, "Connection");
-               if (!conn_header ||
-                   (!soup_header_contains (conn_header, "Keep-Alive") &&
-                    !soup_header_contains (conn_header, "close")))
-
-                       soup_message_headers_append (item->msg->request_headers,
-                                                    "Connection", "Keep-Alive");
-       }
+       conn_header = soup_message_headers_get_list (item->msg->request_headers, "Connection");
+       if (!conn_header ||
+           (!soup_header_contains (conn_header, "Keep-Alive") &&
+            !soup_header_contains (conn_header, "close")))
+               soup_message_headers_append (item->msg->request_headers,
+                                            "Connection", "Keep-Alive");
 
        g_signal_emit (session, signals[REQUEST_STARTED], 0,
                       item->msg, soup_connection_get_socket (item->conn));
@@ -1507,20 +1493,6 @@ soup_session_set_item_status (SoupSession          *session,
 }
 
 static void
-got_headers_cb (SoupMessage *msg, gpointer data)
-{
-       SoupMessageQueueItem *item = data;
-       SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (item->session);
-       SoupSessionHost *host;
-
-       /* Update the HTTP version to use for messages to this host */
-       g_mutex_lock (priv->host_lock);
-       host = get_host_for_message (item->session, SOUP_MESSAGE (msg));
-       host->http_version = soup_message_get_http_version (msg);
-       g_mutex_unlock (priv->host_lock);
-}
-
-static void
 queue_message (SoupSession *session, SoupMessage *msg,
               SoupSessionCallback callback, gpointer user_data)
 {
@@ -1541,9 +1513,6 @@ queue_message (SoupSession *session, SoupMessage *msg,
                        G_CALLBACK (redirect_handler), item);
        }
 
-       /* Used to keep track of the HTTP version used by the host */
-       g_signal_connect (msg, "got-headers", G_CALLBACK (got_headers_cb), item);
-
        g_signal_emit (session, signals[REQUEST_QUEUED], 0, msg);
 }