]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http_fecth: Implement body_len and body_size sample fetches for the HTX
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 12 Dec 2018 13:11:22 +0000 (14:11 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 14 Dec 2018 15:03:39 +0000 (16:03 +0100)
HTX implementation for these 2 sample fetches was missing. This patch fills this
gap.

src/http_fetch.c

index 68c455cb8b019b22afed8e256fd0c1f2ad43cfd3..292da21873d9cf8956eb78a04dfae5a49503e7b7 100644 (file)
@@ -917,7 +917,28 @@ static int smp_fetch_body_len(const struct arg *args, struct sample *smp, const
 {
        if (IS_HTX_SMP(smp) || (smp->px->mode == PR_MODE_TCP)) {
                /* HTX version */
-               return 0; /* TODO: to be implemented */
+               struct htx *htx = smp_prefetch_htx(smp, args);
+               struct htx_blk *blk;
+               unsigned long long len = 0;
+
+               if (!htx)
+                       return 0;
+
+               len = htx->data;
+
+               /* Remove the length of headers part */
+               blk = htx_get_head_blk(htx);
+               while (blk) {
+                       len -= htx_get_blksz(blk);
+                       if (htx_get_blk_type(blk) == HTX_BLK_EOH)
+                               break;
+                       blk = htx_get_next_blk(htx, blk);
+               }
+
+               smp->data.type = SMP_T_SINT;
+               smp->data.u.sint = len;
+
+               smp->flags = SMP_F_VOL_TEST;
        }
        else {
                /* LEGACY version */
@@ -947,7 +968,30 @@ static int smp_fetch_body_size(const struct arg *args, struct sample *smp, const
 {
        if (IS_HTX_SMP(smp) || (smp->px->mode == PR_MODE_TCP)) {
                /* HTX version */
-               return 0; /* TODO: to be implemented */
+               struct htx *htx = smp_prefetch_htx(smp, args);
+               struct htx_blk *blk;
+               unsigned long long len = 0;
+
+               if (!htx)
+                       return 0;
+
+               len = htx->data;
+
+               /* Remove the length of headers part */
+               blk = htx_get_head_blk(htx);
+               while (blk) {
+                       len -= htx_get_blksz(blk);
+                       if (htx_get_blk_type(blk) == HTX_BLK_EOH)
+                               break;
+                       blk = htx_get_next_blk(htx, blk);
+               }
+               if (htx->extra != ULLONG_MAX)
+                       len += htx->extra;
+
+               smp->data.type = SMP_T_SINT;
+               smp->data.u.sint = len;
+
+               smp->flags = SMP_F_VOL_TEST;
        }
        else {
                /* LEGACY version */