]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-ana: Add a txn flag to support soft/strict message rewrites
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 12 Dec 2019 15:41:00 +0000 (16:41 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 20 Jan 2020 14:18:45 +0000 (15:18 +0100)
the HTTP_MSGF_SOFT_RW flag must now be set on the HTTP transaction to ignore
rewrite errors on a message, from HTTP rules. The mode is called the soft
rewrites. If thes flag is not set, strict rewrites are performed. In this mode,
if a rewrite error occurred, an internal error is reported.

For now, HTTP_MSGF_SOFT_RW is always set and there is no way to switch a
transaction in strict mode.

include/types/http_ana.h
src/http_ana.c

index dd55eb8816bd29be79e4afa153a64f6366223e54..a352a99194fb20939732943b3883ab279f47fdc0 100644 (file)
@@ -87,7 +87,7 @@
 #define HTTP_MSGF_XFER_LEN    0x00000004  /* message xfer size can be determined */
 #define HTTP_MSGF_VER_11      0x00000008  /* the message is HTTP/1.1 or above */
 
-/* unused: 0x00000010 */
+#define HTTP_MSGF_SOFT_RW     0x00000010  /* soft header rewrites, no error triggered */
 
 #define HTTP_MSGF_COMPRESSING 0x00000020  /* data compression is in progress */
 
index 5e8d0ab18bcec9a5c29e8a0c5d3db7c2c38714f6..5b49e3438d4ca5077146707cfd3b5ce45e0cef69 100644 (file)
@@ -3066,6 +3066,11 @@ static enum rule_result http_req_get_intercept_rule(struct proxy *px, struct lis
                                                _HA_ATOMIC_ADD(&s->be->be_counters.failed_rewrites, 1);
                                        if (sess->listener->counters)
                                                _HA_ATOMIC_ADD(&sess->listener->counters->failed_rewrites, 1);
+
+                                       if (!(txn->req.flags & HTTP_MSGF_SOFT_RW)) {
+                                               rule_ret = HTTP_RULE_RES_ERROR;
+                                               goto end;
+                                       }
                                }
                                free_trash_chunk(replace);
                                break;
@@ -3426,6 +3431,11 @@ resume_execution:
                                                _HA_ATOMIC_ADD(&sess->listener->counters->failed_rewrites, 1);
                                        if (objt_server(s->target))
                                                _HA_ATOMIC_ADD(&__objt_server(s->target)->counters.failed_rewrites, 1);
+
+                                       if (!(txn->rsp.flags & HTTP_MSGF_SOFT_RW)) {
+                                               rule_ret = HTTP_RULE_RES_ERROR;
+                                               goto end;
+                                       }
                                }
                                free_trash_chunk(replace);
                                break;
@@ -5535,13 +5545,13 @@ struct http_txn *http_alloc_txn(struct stream *s)
 
 void http_txn_reset_req(struct http_txn *txn)
 {
-       txn->req.flags = 0;
+       txn->req.flags = HTTP_MSGF_SOFT_RW;
        txn->req.msg_state = HTTP_MSG_RQBEFORE; /* at the very beginning of the request */
 }
 
 void http_txn_reset_res(struct http_txn *txn)
 {
-       txn->rsp.flags = 0;
+       txn->rsp.flags = HTTP_MSGF_SOFT_RW;
        txn->rsp.msg_state = HTTP_MSG_RPBEFORE; /* at the very beginning of the response */
 }