]> 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)
committerGitLab <gitlab@git.dovecot.net>
Fri, 22 Apr 2016 19:30:12 +0000 (22:30 +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 4cafb253a4ed9e17d858cb1d5af35702803cde09..48612813b8a0101036a09c105523e2d050acfb98 100644 (file)
@@ -134,6 +134,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 3ca47d9ce814dd193daa08b3136ec328785e7439..5663392b5a13bba74a508788d8e2d72592463295 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)
 {
@@ -1018,7 +1023,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 75cdac58fd50f5086eb8cd9868b7051b5c173d04..2df8d9ee03c1c70b0790fcdc8e6caa74b2cba2e9 100644 (file)
@@ -237,6 +237,7 @@ void http_client_request_set_ssl(struct http_client_request *req,
    non-urgent request. Also, if no idle connection is available, a new
    connection is created. Urgent requests are never pipelined. */
 void http_client_request_set_urgent(struct http_client_request *req);
+void http_client_request_set_preserve_exact_reason(struct http_client_request *req);
 
 /* add a custom header to the request. This can override headers that are
    otherwise created implicitly. */