Skip to content

Commit

Permalink
lib-http: Assign an ID for each HTTP request and log it in debug lines.
Browse files Browse the repository at this point in the history
The ID stays the same when request is retried. Added a "Req" prefix so it's
easier to search for the IDs. Based on patch by Stephan Bosch.
  • Loading branch information
sirainen committed Jan 16, 2016
1 parent bd06c77 commit 47a53a8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/lib-http/http-client-private.h
Expand Up @@ -60,6 +60,7 @@ struct http_client_request {
pool_t pool;
unsigned int refcount;
const char *label;
unsigned int id;

struct http_client_request *prev, *next;

Expand Down Expand Up @@ -445,7 +446,7 @@ static inline const char *
http_client_request_label(struct http_client_request *req)
{
if (req->label == NULL) {
return t_strdup_printf("[%s %s%s]",
return t_strdup_printf("[Req%u: %s %s%s]", req->id,
req->method, http_url_create(&req->origin_url), req->target);
}
return req->label;
Expand Down
4 changes: 3 additions & 1 deletion src/lib-http/http-client-request.c
Expand Up @@ -63,6 +63,7 @@ static struct http_client_request *
http_client_request_new(struct http_client *client, const char *method,
http_client_request_callback_t *callback, void *context)
{
static unsigned int id_counter = 0;
pool_t pool;
struct http_client_request *req;

Expand All @@ -71,6 +72,7 @@ http_client_request_new(struct http_client *client, const char *method,
req->pool = pool;
req->refcount = 1;
req->client = client;
req->id = ++id_counter;
req->method = p_strdup(pool, method);
req->callback = callback;
req->context = context;
Expand Down Expand Up @@ -485,7 +487,7 @@ static void http_client_request_do_submit(struct http_client_request *req)
req->authority = p_strdup(req->pool, authority);

/* debug label */
req->label = p_strdup_printf(req->pool, "[%s %s]", req->method, target);
req->label = p_strdup_printf(req->pool, "[Req%u: %s %s]", req->id, req->method, target);

/* update request target */
if (req->connect_tunnel || have_proxy)
Expand Down

0 comments on commit 47a53a8

Please sign in to comment.