diff -ru libsoup.orig/soup-session.c libsoup/soup-session.c
--- libsoup.orig/soup-session.c	2009-07-01 10:46:10.649187950 +0200
+++ libsoup/soup-session.c	2009-07-01 17:02:38.785165915 +0200
@@ -1025,17 +1025,16 @@
 static void
 tunnel_connected (SoupSession *session, SoupMessage *msg, gpointer user_data)
 {
-	if (SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
+	if (!SOUP_STATUS_IS_SUCCESSFUL (msg->status_code)) {
 		SoupSessionPrivate *priv = SOUP_SESSION_GET_PRIVATE (session);
-		SoupMessageQueueItem *item =
-			soup_message_queue_lookup (priv->queue, msg);
+		SoupSessionHost *host = get_host_for_message (session, msg);
+		SoupMessageQueueItem *item;
 
-		/* Clear the connection's proxy_uri, since it is now
-		 * (effectively) directly connected.
-		 */
-		g_object_set (item->conn,
-			      SOUP_CONNECTION_PROXY_URI, NULL,
-			      NULL);
+		/* cancel all pendings message in the queue */
+		for (item = soup_message_queue_first (priv->queue); item; item = soup_message_queue_next (priv->queue, item)) {
+			if (get_host_for_message (session, item->msg) == host)
+				soup_session_cancel_message (session, item->msg, msg->status_code);
+		}
 	}
 }
 
@@ -1208,6 +1207,14 @@
 	}
 
 	if (!SOUP_MESSAGE_IS_STARTING (msg)) {
+
+		/*
+		 * call the message attached callback if any
+		 */
+		if(item->callback != NULL) {
+			item->callback(session, msg, item->callback_data);
+		}
+
 		soup_message_queue_remove (priv->queue, item);
 		g_signal_handlers_disconnect_by_func (msg, message_finished, item);
 		/* g_signal_handlers_disconnect_by_func doesn't work if you
