From: Stephan Bosch Date: Fri, 17 Jun 2016 14:59:15 +0000 (+0200) Subject: lib-http: client: Implemented no_auto_retry setting that disables all automatic reque... X-Git-Tag: 2.2.25.rc1~106 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=29d5559f1934ec12ccad93413502c0873f18b9b5;p=thirdparty%2Fdovecot%2Fcore.git lib-http: client: Implemented no_auto_retry setting that disables all automatic request retries. 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(). --- diff --git a/src/lib-http/http-client-connection.c b/src/lib-http/http-client-connection.c index 9b8a6c3e05..66adf75040 100644 --- a/src/lib-http/http-client-connection.c +++ b/src/lib-http/http-client-connection.c @@ -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); } diff --git a/src/lib-http/http-client.c b/src/lib-http/http-client.c index 321b165ffe..14814f8047 100644 --- a/src/lib-http/http-client.c +++ b/src/lib-http/http-client.c @@ -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; diff --git a/src/lib-http/http-client.h b/src/lib-http/http-client.h index d482bb1399..37bdc0220e 100644 --- a/src/lib-http/http-client.h +++ b/src/lib-http/http-client.h @@ -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;