]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: client: Trigger special events when a request is finished, retried or redir...
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 21 Jan 2018 14:46:49 +0000 (15:46 +0100)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Mon, 12 Mar 2018 09:07:37 +0000 (11:07 +0200)
src/lib-http/http-client-request.c

index ec7cbd120e5289f8e5bcef007945b76f4404f474..5fb6cd72afa763d6d25a1c174e5a15aee9c4094b 100644 (file)
@@ -61,6 +61,15 @@ http_client_request_update_event(struct http_client_request *req)
                "request %s: ", http_client_request_label(req)));
 }
 
+static struct event_passthrough *
+http_client_request_result_event(struct http_client_request *req)
+{
+       return event_create_passthrough(req->event)->
+               add_int("status_code", req->last_status)->
+               add_int("attempts", req->attempts)->
+               add_int("redirects", req->redirects);
+}
+
 static struct http_client_request *
 http_client_request_new(struct http_client *client, const char *method, 
                    http_client_request_callback_t *callback, void *context)
@@ -1409,6 +1418,10 @@ void http_client_request_error(struct http_client_request **_req,
        req->state = HTTP_REQUEST_STATE_ABORTED;
        req->last_status = status;
 
+       e_debug(http_client_request_result_event(req)->
+               set_name("http_request_finished")->event(),
+               "Error: %u %s", status, error);
+
        if (req->queue != NULL)
                http_client_queue_drop_request(req->queue, req);
 
@@ -1442,6 +1455,13 @@ void http_client_request_abort(struct http_client_request **_req)
        if (req->last_status == 0)
                req->last_status = HTTP_CLIENT_REQUEST_ERROR_ABORTED;
 
+       if (req->state > HTTP_REQUEST_STATE_NEW &&
+           req->delayed_error_status == 0) {
+               e_debug(http_client_request_result_event(req)->
+                       set_name("http_request_finished")->event(),
+                       "Aborted");
+       }
+
        /* release payload early (prevents server/client deadlock in proxy) */
        if (!sending && req->payload_input != NULL)
                i_stream_unref(&req->payload_input);
@@ -1463,9 +1483,9 @@ void http_client_request_finish(struct http_client_request *req)
 
        i_assert(req->refcount > 0);
 
-       e_debug(event_create_passthrough(req->event)->
-               add_int("attempts", req->attempts)->
-               set_name("http_request_finished")->event(), "Finished");
+       e_debug(http_client_request_result_event(req)->
+               set_name("http_request_finished")->event(),
+               "Finished");
 
        req->callback = NULL;
        req->state = HTTP_REQUEST_STATE_FINISHED;
@@ -1539,8 +1559,10 @@ void http_client_request_redirect(struct http_client_request *req,
 
        origin_url = http_url_create(&req->origin_url);
 
-       e_debug(req->event, "Redirecting to %s%s",
-               origin_url, target);
+       e_debug(http_client_request_result_event(req)->
+               set_name("http_request_redirected")->event(),
+               "Redirecting to %s%s (redirects=%u)",
+               origin_url, target, req->redirects);
 
        req->label = p_strdup_printf(req->pool, "[%s %s%s]",
                req->method, origin_url, req->target);
@@ -1618,7 +1640,10 @@ bool http_client_request_try_retry(struct http_client_request *req)
                return FALSE;
        req->attempts++;
 
-       e_debug(req->event, "Retrying (attempts=%d)", req->attempts);
+       e_debug(http_client_request_result_event(req)->
+               set_name("http_request_retried")->event(),
+               "Retrying (attempts=%d)", req->attempts);
+
        if (req->callback != NULL)
                http_client_request_resubmit(req);
        return TRUE;