]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: Include information about number of request attempts and its timing in...
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 19 Apr 2016 13:55:02 +0000 (16:55 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 26 Apr 2016 08:27:44 +0000 (11:27 +0300)
Because the reason is usually logged as part of the error string, this
causes all of the error messages to include the attempts count and how long
the requests took in total. This should make it easier to understand problems
in error logs.

http_client_request_set_preserve_exact_reason() can be used to disable
modifying the reason string. This may also apply to other reason
modifications that may be done in the future.

src/lib-http/http-client-private.h
src/lib-http/http-client-request.c
src/lib-http/http-client.h

index f34a4ceb1d86f46db2dfc186457ccc79fdb12d58..27ad2d1fc4be840fac5ebc8fe944de14b79d7a03 100644 (file)
@@ -122,6 +122,7 @@ struct http_client_request {
        unsigned int connect_tunnel:1;
        unsigned int connect_direct:1;
        unsigned int ssl_tunnel:1;
+       unsigned int preserve_exact_reason:1;
 };
 
 struct http_client_connection {
index cde2db97c64e2872e0068abfe7f77f1a9802fb0a..961205835873271ee9fa2449d6e1f56a0e7a7676 100644 (file)
@@ -246,6 +246,11 @@ void http_client_request_set_urgent(struct http_client_request *req)
        req->urgent = TRUE;
 }
 
+void http_client_request_set_preserve_exact_reason(struct http_client_request *req)
+{
+       req->preserve_exact_reason = TRUE;
+}
+
 void http_client_request_add_header(struct http_client_request *req,
                                    const char *key, const char *value)
 {
@@ -1016,7 +1021,18 @@ bool http_client_request_callback(struct http_client_request *req,
 
        req->callback = NULL;
        if (callback != NULL) {
-               callback(response, req->context);
+               struct http_response response_copy = *response;
+
+               if (req->attempts > 0 && !req->preserve_exact_reason) {
+                       unsigned int total_msecs =
+                               timeval_diff_msecs(&ioloop_timeval, &req->submit_time);
+                       response_copy.reason = t_strdup_printf(
+                               "%s (%u attempts in %u.%03u secs)",
+                               response_copy.reason, req->attempts,
+                               total_msecs/1000, total_msecs%1000);
+               }
+
+               callback(&response_copy, req->context);
                if (req->attempts != orig_attempts) {
                        /* retrying */
                        req->callback = callback;
index ddc221e538ad4364b2c5aa62a05b91560962d416..fba5d1e03630bf3a121734cfb20b46af6a106fb0 100644 (file)
@@ -194,6 +194,7 @@ void http_client_request_set_port(struct http_client_request *req,
 void http_client_request_set_ssl(struct http_client_request *req,
        bool ssl);
 void http_client_request_set_urgent(struct http_client_request *req);
+void http_client_request_set_preserve_exact_reason(struct http_client_request *req);
 
 void http_client_request_add_header(struct http_client_request *req,
                                    const char *key, const char *value);