From 7ccdd8dad9a3c3ceb35d154254edda7203b98ce5 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Fri, 7 Sep 2018 14:01:39 +0200 Subject: [PATCH] MEDIUM: snapshot: implement a show() callback and use it for HTTP The HTTP dumps are now configurable in the code : "show errors" now calls a protocol-specific function to emit the decoded output. For now only HTTP is implemented. --- include/types/proxy.h | 1 + src/proto_http.c | 29 +++++++++++++++++++++-------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/types/proxy.h b/include/types/proxy.h index 13cc2a4e8..9695b9c2d 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -239,6 +239,7 @@ struct error_snapshot { unsigned int ev_id; /* event number (counter incremented for each capture) */ /* @68: 4 bytes hole here */ struct sockaddr_storage src; /* client's address */ + void (*show)(struct buffer *, const struct error_snapshot *); /* dump function */ /**** protocol-specific part ****/ union error_snapshot_ctx ctx; diff --git a/src/proto_http.c b/src/proto_http.c index 65f0636e8..00be9fe37 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -8008,6 +8008,22 @@ int stats_check_uri(struct stream_interface *si, struct http_txn *txn, struct pr return 1; } +/* Append the description of what is present in error snapshot into . + * The description must be small enough to always fit in a trash. The output + * buffer may be the trash so the trash must not be used inside this function. + */ +void http_show_error_snapshot(struct buffer *out, const struct error_snapshot *es) +{ + chunk_appendf(&trash, + " stream #%d, stream flags 0x%08x, tx flags 0x%08x\n" + " HTTP msg state %s(%d), msg flags 0x%08x\n" + " HTTP chunk len %lld bytes, HTTP body len %lld bytes, channel flags 0x%08x :\n", + es->ctx.http.sid, es->ctx.http.s_flags, es->ctx.http.t_flags, + h1_msg_state_str(es->ctx.http.state), es->ctx.http.state, + es->ctx.http.m_flags, es->ctx.http.m_clen, + es->ctx.http.m_blen, es->ctx.http.b_flags); +} + /* * Capture a bad request or response and archive it in the proxy's structure. * By default it tries to report the error position as msg->err_pos. However if @@ -8063,6 +8079,7 @@ void http_capture_bad_message(struct proxy *proxy, struct error_snapshot *es, st es->buf_ofs = 0; /* http-specific part now */ + es->show = http_show_error_snapshot; es->ctx.http.sid = s->uniq_id; es->ctx.http.state = state; es->ctx.http.b_flags = chn->flags; @@ -12782,14 +12799,10 @@ static int cli_io_handler_show_errors(struct appctx *appctx) global.tune.bufsize - es->buf_out - es->buf_len, es->buf_len, es->buf_wrap, es->buf_err); - chunk_appendf(&trash, - " stream #%d, stream flags 0x%08x, tx flags 0x%08x\n" - " HTTP msg state %s(%d), msg flags 0x%08x\n" - " HTTP chunk len %lld bytes, HTTP body len %lld bytes, channel flags 0x%08x :\n \n", - es->ctx.http.sid, es->ctx.http.s_flags, es->ctx.http.t_flags, - h1_msg_state_str(es->ctx.http.state), es->ctx.http.state, - es->ctx.http.m_flags, es->ctx.http.m_clen, - es->ctx.http.m_blen, es->ctx.http.b_flags); + if (es->show) + es->show(&trash, es); + + chunk_appendf(&trash, " \n"); if (ci_putchk(si_ic(si), &trash) == -1) { /* Socket buffer full. Let's try again later from the same point */