commit f406ea9dac5a414bb2c53350a25183ccdfd2ed09
Author: Dirkjan Ochtman <d.ochtman@activevideo.com>
Date:   Mon Dec 23 16:19:19 2013 +0100

    Add (private) flag keep_connection to SoupSocket

diff --git a/libsoup/soup-misc-private.h b/libsoup/soup-misc-private.h
index 50a3b98..cbb744f 100644
--- a/libsoup/soup-misc-private.h
+++ b/libsoup/soup-misc-private.h
@@ -46,6 +46,7 @@ GIOStream *soup_socket_get_iostream   (SoupSocket *sock);
 
 #define SOUP_SOCKET_CLEAN_DISPOSE "clean-dispose"
 #define SOUP_SOCKET_PROXY_RESOLVER "proxy-resolver"
+#define SOUP_SOCKET_KEEP_CONNECTION "keep-connection"
 SoupURI *soup_socket_get_http_proxy_uri (SoupSocket *sock);
 
 /* At some point it might be possible to mark additional methods
diff --git a/libsoup/soup-socket.c b/libsoup/soup-socket.c
index e0748fd..76541c2 100644
--- a/libsoup/soup-socket.c
+++ b/libsoup/soup-socket.c
@@ -60,6 +60,7 @@ enum {
 	PROP_TLS_CERTIFICATE,
 	PROP_TLS_ERRORS,
 	PROP_PROXY_RESOLVER,
+	PROP_KEEP_CONNECTION,
 
 	LAST_PROP
 };
@@ -81,6 +82,7 @@ typedef struct {
 	guint clean_dispose:1;
 	guint use_thread_context:1;
 	gpointer ssl_creds;
+	gboolean keep_connection;
 
 	GMainContext   *async_context;
 	GSource        *watch_src;
@@ -136,14 +138,15 @@ soup_socket_finalize (GObject *object)
 			g_warning ("Disposing socket %p during connect", object);
 		g_object_unref (priv->connect_cancel);
 	}
-	if (priv->gsock) {
+	if (priv->gsock && !priv->keep_connection) {
 		if (priv->clean_dispose)
 			g_warning ("Disposing socket %p while still connected", object);
 		disconnect_internal (SOUP_SOCKET (object), TRUE);
 	}
 
 	g_clear_object (&priv->conn);
-	g_clear_object (&priv->iostream);
+	if (!priv->keep_connection)
+		g_clear_object (&priv->iostream);
 	g_clear_object (&priv->istream);
 	g_clear_object (&priv->ostream);
 
@@ -229,6 +232,9 @@ soup_socket_set_property (GObject *object, guint prop_id,
 	case PROP_CLEAN_DISPOSE:
 		priv->clean_dispose = g_value_get_boolean (value);
 		break;
+	case PROP_KEEP_CONNECTION:
+		priv->keep_connection = g_value_get_boolean (value);
+		break;
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -287,6 +293,8 @@ soup_socket_get_property (GObject *object, guint prop_id,
 	case PROP_PROXY_RESOLVER:
 		g_value_set_object (value, priv->proxy_resolver);
 		break;
+	case PROP_KEEP_CONNECTION:
+		g_value_set_boolean (value, priv->keep_connection);
 	default:
 		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -628,6 +636,14 @@ soup_socket_class_init (SoupSocketClass *socket_class)
 				     "GProxyResolver to use",
 				     G_TYPE_PROXY_RESOLVER,
 				     G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
+
+	g_object_class_install_property (
+		object_class, PROP_KEEP_CONNECTION,
+		g_param_spec_boolean ("keep-connection",
+				    "Keep connection",
+				    "Whether the connection is kept (and iostream kept alive) on disposal",
+				    FALSE,
+				    G_PARAM_READWRITE));
 }
 
 
