On Mon, 2011-03-28 at 07:22 +0200, Willy Tarreau wrote:
> On Sun, Mar 27, 2011 at 09:28:15PM -0400, Roy Smith wrote:
> > Thanks! Looks like "capture request header" does exactly what I want.
> >
> > Well, mostly. This gets me logging if the header exists. Now I need to
> > figure out how to insert the header if it doesn't (taking us back to the
> > conversation we had in January).
>
> Then maybe you just have to change the code in the early processing,
> just before the header captures ?
OK, this looks like it works. I still need to do something smarter
about generating the unique ids (some combination of hostid, pid, and
time, and counter should do it), and adding a way to control this from
the config file. Before I get too deep into this, does the following
patch (against haproxy-1.4.11) look reasonable for the basics?
--- a/src/proto_http.c Sat Mar 26 12:38:10 2011 -0400
+++ b/src/proto_http.c Mon Mar 28 13:41:04 2011 -0400
@@ -2713,6 +2713,19 @@
/* transfer length unknown*/
txn->flags &= ~TX_REQ_XFER_LEN;
+ /* 4b: Insert header for tracing, if needed */
+ ctx.idx = 0;
+ {
+ const char hdr[] = "X-Unique-Id";
+ const size_t hdr_len = sizeof(hdr);
+ if (! http_find_header(hdr, msg->sol, &txn->hdr_idx, &ctx)) {
+ static int id_counter = 0;
+ char hdr_val[hdr_len + sizeof(": 1234567890") + 1];
+ snprintf(hdr_val, sizeof(hdr_val), "%s: %d", hdr,
id_counter++);
+ http_header_add_tail(req, &txn->req, &txn->hdr_idx,
hdr_val);
+ }
+ }
+
/* 5: we may need to capture headers */
if (unlikely((s->logs.logwait & LW_REQHDR) && s->fe->req_cap))
capture_headers(msg->sol, &txn->hdr_idx,
@@ -2757,7 +2770,6 @@
*/
use_close_only = 0;
- ctx.idx = 0;
/* set TE_CHNK and XFER_LEN only if "chunked" is seen last */
while ((txn->flags & TX_REQ_VER_11) &&
http_find_header2("Transfer-Encoding", 17, msg->sol,
&txn->hdr_idx, &ctx)) {