changeset 16849:ad46c778981d

lib-http: http-client: When client request is retried based on a response received from server, return full response to caller if retry is not possible. Before, it would construct a dummy-response that basically retains only the status and reason elements. This is currently only relevant for the way a 417 Expectation Failed response from the server is handled.
author Stephan Bosch <stephan@rename-it.nl>
date Sat, 12 Oct 2013 10:54:10 +0300
parents aa39d877d2c5
children 2d44e9025af3
files src/lib-http/http-client-connection.c src/lib-http/http-client-private.h src/lib-http/http-client-request.c
diffstat 3 files changed, 13 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-http/http-client-connection.c	Sat Oct 12 10:53:16 2013 +0300
+++ b/src/lib-http/http-client-connection.c	Sat Oct 12 10:54:10 2013 +0300
@@ -593,7 +593,7 @@
 				req->payload_sync = FALSE;
 				conn->output_locked = FALSE;
 				conn->peer->no_payload_sync = TRUE;
-				http_client_request_retry(req, response.status, response.reason);
+				http_client_request_retry_response(req, &response);
 	
 			} else if (response.status / 100 == 3 && response.status != 304 &&
 				response.location != NULL) {
--- a/src/lib-http/http-client-private.h	Sat Oct 12 10:53:16 2013 +0300
+++ b/src/lib-http/http-client-private.h	Sat Oct 12 10:54:10 2013 +0300
@@ -240,6 +240,8 @@
 void http_client_request_resubmit(struct http_client_request *req);
 void http_client_request_retry(struct http_client_request *req,
 	unsigned int status, const char *error);
+void http_client_request_retry_response(struct http_client_request *req,
+	struct http_response *response);
 void http_client_request_error(struct http_client_request *req,
 	unsigned int status, const char *error);
 void http_client_request_redirect(struct http_client_request *req,
--- a/src/lib-http/http-client-request.c	Sat Oct 12 10:53:16 2013 +0300
+++ b/src/lib-http/http-client-request.c	Sat Oct 12 10:54:10 2013 +0300
@@ -773,6 +773,16 @@
 		http_client_request_error(req, status, error);
 }
 
+void http_client_request_retry_response(struct http_client_request *req,
+	struct http_response *response)
+{
+	if (!http_client_request_try_retry(req)) {
+		i_assert(req->submitted || req->state >= HTTP_REQUEST_STATE_FINISHED);
+		(void)http_client_request_callback(req, response);
+		http_client_request_unref(&req);
+	}
+}
+
 bool http_client_request_try_retry(struct http_client_request *req)
 {
 	/* limit the number of attempts for each request */