From 473e880a255886b9ecd55c49709ef570fed7aad6 Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Tue, 14 Jan 2020 11:12:37 +0100 Subject: [PATCH] MINOR: http-ana: Add an error message in the txn and send it when defined It is now possible to set the error message to return to client in the HTTP transaction. If it is defined, this error message is used instead of proxy's errors or default errors. --- include/types/http_ana.h | 1 + src/http_ana.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/types/http_ana.h b/include/types/http_ana.h index a352a9919..5a7ced7b0 100644 --- a/include/types/http_ana.h +++ b/include/types/http_ana.h @@ -175,6 +175,7 @@ struct http_txn { enum http_meth_t meth; /* HTTP method */ /* 1 unused byte here */ short status; /* HTTP status from the server, negative if from proxy */ + struct buffer *errmsg; /* custom HTTP error message to use as reply */ char cache_hash[20]; /* Store the cache hash */ char *uri; /* first line if log needed, NULL otherwise */ diff --git a/src/http_ana.c b/src/http_ana.c index 574f6eb01..10ee24111 100644 --- a/src/http_ana.c +++ b/src/http_ana.c @@ -4597,7 +4597,9 @@ struct buffer *http_error_message(struct stream *s) { const int msgnum = http_get_status_idx(s->txn->status); - if (s->be->errmsg[msgnum]) + if (s->txn && s->txn->errmsg) + return s->txn->errmsg; + else if (s->be->errmsg[msgnum]) return s->be->errmsg[msgnum]; else if (strm_fe(s)->errmsg[msgnum]) return strm_fe(s)->errmsg[msgnum]; @@ -5024,6 +5026,7 @@ void http_init_txn(struct stream *s) ? (TX_NOT_FIRST|TX_WAIT_NEXT_RQ) : 0); txn->status = -1; + txn->errmsg = NULL; *(unsigned int *)txn->cache_hash = 0; txn->cookie_first_date = 0;