]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Implemented no_auto_retry setting that disables all automatic reque...
authorStephan Bosch <stephan@dovecot.fi>
Fri, 17 Jun 2016 14:59:15 +0000 (16:59 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 20 Jun 2016 00:25:14 +0000 (03:25 +0300)
This currently only applies to requests sent over a connection that is subsequently lost before a response is received.
Before, such requests were always implicitly resumbitted for a new connection, without the application knowing about it.
By enabling the no_auto_retry client setting, the application is always notified of connection loss through the request's response callback.
As a consequence, requests need to be retried explicitly using the http_client_request_try_retry().

src/lib-http/http-client-connection.c
src/lib-http/http-client.c
src/lib-http/http-client.h

index 9b8a6c3e05549c06ca84524607b2c6e8ea3e407f..66adf75040de1bedd054fb54b90328bc7cbacca9 100644 (file)
@@ -66,13 +66,19 @@ static void
 http_client_connection_retry_requests(struct http_client_connection *conn,
        unsigned int status, const char *error)
 {
+       const struct http_client_settings *set = &conn->client->set;
        struct http_client_request *req, **req_idx;
 
        if (!array_is_created(&conn->request_wait_list))
                return;
 
-       http_client_connection_debug(conn,
-               "Retrying pending requests");
+       if (set->no_auto_retry) {
+               http_client_connection_debug(conn,
+                       "Aborting pending requests with error");
+       } else {
+               http_client_connection_debug(conn,
+                       "Retrying pending requests");
+       }
 
        array_foreach_modifiable(&conn->request_wait_list, req_idx) {
                req = *req_idx;
@@ -81,8 +87,12 @@ http_client_connection_retry_requests(struct http_client_connection *conn,
                if (!http_client_request_unref(req_idx))
                        continue;
                /* retry the request, which may drop it */
-               if (req->state < HTTP_REQUEST_STATE_FINISHED)
-                       http_client_request_retry(req, status, error);
+               if (req->state < HTTP_REQUEST_STATE_FINISHED) {
+                       if (set->no_auto_retry)
+                               http_client_request_error(&req, status, error);
+                       else
+                               http_client_request_retry(req, status, error);
+               }
        }       
        array_clear(&conn->request_wait_list);
 }
index 321b165ffe752e39862094ada580931d107f6437..14814f8047e2f2e2024866a61b9bd9a03c2b7b8c 100644 (file)
@@ -137,6 +137,7 @@ struct http_client *http_client_init(const struct http_client_settings *set)
                        HTTP_CLIENT_DEFAULT_BACKOFF_MAX_TIME_MSECS :
                        set->connect_backoff_max_time_msecs;
        client->set.no_auto_redirect = set->no_auto_redirect;
+       client->set.no_auto_retry = set->no_auto_retry;
        client->set.no_ssl_tunnel = set->no_ssl_tunnel;
        client->set.max_redirects = set->max_redirects;
        client->set.response_hdr_limits = set->response_hdr_limits;
index d482bb1399dafff28c07b95af20ae96c6073a89d..37bdc0220ed0af22bd01af31080f087dc5d655df 100644 (file)
@@ -72,6 +72,9 @@ struct http_client_settings {
        /* don't automatically act upon redirect responses */
        bool no_auto_redirect;
 
+       /* never automatically retry requests */
+       bool no_auto_retry;
+
        /* if we use a proxy, delegate SSL negotiation to proxy, rather than
           creating a CONNECT tunnel through the proxy for the SSL link */
        bool no_ssl_tunnel;