SoupMessage: Add SOUP_MESSAGE_IDEMPOTENT flag
authorMilan Crha <mcrha@redhat.com>
Mon, 13 Aug 2012 12:27:02 +0000 (14:27 +0200)
committerDan Winship <danw@gnome.org>
Sun, 19 Aug 2012 19:06:12 +0000 (15:06 -0400)
In particular, this lets the app indicate that it's OK to use an
existing connection when sending a POST.

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

libsoup/soup-message.c
libsoup/soup-message.h
libsoup/soup-session.c

index 3e1112e..2271cd0 100644 (file)
@@ -1453,7 +1453,12 @@ soup_message_cleanup_response (SoupMessage *req)
  * @SOUP_MESSAGE_NEW_CONNECTION: The message should be sent on a
  *   newly-created connection, not reusing an existing persistent
  *   connection. Note that messages with non-idempotent
- *   #SoupMessage:method<!-- -->s behave this way by default.
+ *   #SoupMessage:method<!-- -->s behave this way by default,
+ *   unless #SOUP_MESSAGE_IDEMPOTENT is set.
+ * @SOUP_MESSAGE_IDEMPOTENT: The message is considered idempotent,
+ *   regardless its #SoupMessage:method, and allows reuse of existing
+ *   idle connections, instead of always requiring a new one, unless
+ *   #SOUP_MESSAGE_NEW_CONNECTION is set.
  *
  * Various flags that can be set on a #SoupMessage to alter its
  * behavior.
index d3c7e3c..d74ee13 100644 (file)
@@ -119,7 +119,8 @@ typedef enum {
 #endif
        SOUP_MESSAGE_CONTENT_DECODED      = (1 << 4),
        SOUP_MESSAGE_CERTIFICATE_TRUSTED  = (1 << 5),
-       SOUP_MESSAGE_NEW_CONNECTION       = (1 << 6)
+       SOUP_MESSAGE_NEW_CONNECTION       = (1 << 6),
+       SOUP_MESSAGE_IDEMPOTENT           = (1 << 7)
 } SoupMessageFlags;
 
 void             soup_message_set_flags           (SoupMessage           *msg,
index 7b68d42..90e9189 100644 (file)
@@ -1207,7 +1207,8 @@ soup_session_get_connection (SoupSession *session,
 
        need_new_connection =
                (soup_message_get_flags (item->msg) & SOUP_MESSAGE_NEW_CONNECTION) ||
-               !SOUP_METHOD_IS_IDEMPOTENT (item->msg->method);
+               (!(soup_message_get_flags (item->msg) & SOUP_MESSAGE_IDEMPOTENT) &&
+                !SOUP_METHOD_IS_IDEMPOTENT (item->msg->method));
 
        g_mutex_lock (&priv->conn_lock);