changeset 20364:51790e6d3310

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().
author Stephan Bosch <stephan@dovecot.fi>
date Fri, 17 Jun 2016 16:59:15 +0200
parents 809fe679f218
children c0ec6c81852d
files src/lib-http/http-client-connection.c src/lib-http/http-client.c src/lib-http/http-client.h
diffstat 3 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-http/http-client-connection.c	Fri Jun 17 15:39:36 2016 +0200
+++ b/src/lib-http/http-client-connection.c	Fri Jun 17 16:59:15 2016 +0200
@@ -66,13 +66,19 @@
 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 @@
 		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);
 }
--- a/src/lib-http/http-client.c	Fri Jun 17 15:39:36 2016 +0200
+++ b/src/lib-http/http-client.c	Fri Jun 17 16:59:15 2016 +0200
@@ -137,6 +137,7 @@
 			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;
--- a/src/lib-http/http-client.h	Fri Jun 17 15:39:36 2016 +0200
+++ b/src/lib-http/http-client.h	Fri Jun 17 16:59:15 2016 +0200
@@ -72,6 +72,9 @@
 	/* 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;