]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: Add function to get amount of data in the output buffer
authorChristopher Faulet <cfaulet@haproxy.com>
Wed, 5 Nov 2025 10:36:07 +0000 (11:36 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 6 Nov 2025 14:01:29 +0000 (15:01 +0100)
The helper function applet_output_data() returns the amount of data in the
output buffer of an applet. For applets using the new API, it is based on
data present in the outbuf buffer. For legacy applets, it is based on input
data present in the input channel's buffer. The HTX version,
applet_htx_output_data(), is also available

This patch is related to issue #1617.

include/haproxy/applet.h

index 018290d62bc82a673a54c654c997721cd30b7262..8f2943e6858efaa8fd9a1f523f79d27649ed8200 100644 (file)
@@ -340,6 +340,27 @@ static inline size_t applet_input_data(const struct appctx *appctx)
                return co_data(sc_oc(appctx_sc(appctx)));
 }
 
+/* Returns the amount of HTX data in the output buffer (see applet_get_outbuf) */
+static inline size_t applet_htx_output_data(const struct appctx *appctx)
+{
+       if (appctx_app_test(appctx, APPLET_FL_NEW_API))
+               return htx_used_space(htxbuf(&appctx->outbuf));
+       else
+               return ci_data(sc_ic(appctx_sc(appctx)));
+}
+
+/* Returns the amount of data in the output buffer (see applet_get_outbuf) */
+static inline size_t applet_output_data(const struct appctx *appctx)
+{
+       if (appctx_app_test(appctx, APPLET_FL_HTX))
+               return applet_htx_output_data(appctx);
+
+       if (appctx_app_test(appctx, APPLET_FL_NEW_API))
+               return b_data(&appctx->outbuf);
+       else
+               return ci_data(sc_ic(appctx_sc(appctx)));
+}
+
 /* Skips <len> bytes from the input buffer (see applet_get_inbuf).
  *
  * This is useful when data have been read directly from the buffer. It is