]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-ana: Add an error message in the txn and send it when defined
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 14 Jan 2020 10:12:37 +0000 (11:12 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 20 Jan 2020 14:18:46 +0000 (15:18 +0100)
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
src/http_ana.c

index a352a99194fb20939732943b3883ab279f47fdc0..5a7ced7b0235089ab56af814ea227ff55ea6f227 100644 (file)
@@ -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 */
index 574f6eb01e44e7da0791b92e370606c9fd730b49..10ee24111565ba86472cb0a4f415445aa1746d7e 100644 (file)
@@ -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;