]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
ap_expr now allows kept_body() function to grab/use
authorJim Jagielski <jim@apache.org>
Wed, 20 Jan 2016 16:58:04 +0000 (16:58 +0000)
committerJim Jagielski <jim@apache.org>
Wed, 20 Jan 2016 16:58:04 +0000 (16:58 +0000)
response body if stored in r->kept_body

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1725755 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
docs/manual/expr.xml
server/util_expr_eval.c

diff --git a/CHANGES b/CHANGES
index 2ed95841f121e6c4f5c63debbd945cf05e62b3b1..e83d781ab52ab26e25bf60a43f69a99fa09ea0e1 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.0
 
+  *) ap_expr: expression support for r->kept_body if it exists.
+     [Jim Jagielski]
+
   *) mod_http2: bytes read/written on slave connections are reported via the
      optional mod_logio functions. Fixes PR 58871.
      
index 257eb1d9a4cf1f3ed171ff3822a1ecb91a65e445..c6bb8f00a429f6f0cefd128058bcd1fdf0423ead 100644 (file)
@@ -501,6 +501,8 @@ listfunction ::= listfuncname "<strong>(</strong>" word "<strong>)</strong>"
         <td>Lookup operating system environment variable</td><td></td></tr>
     <tr><td><code>note</code></td>
         <td>Lookup request note</td><td></td></tr>
+    <tr><td><code>kept_body</code></td>
+        <td>Lookup response body if available in <code>r->kept_body</code></td><td></td></tr>
     <tr><td><code>env</code></td>
         <td>Return first match of <code>note</code>, <code>reqenv</code>,
             <code>osenv</code></td><td></td></tr>
index 5a8f207eadce51f96747cea189b9209004e9c2f7..d3c981276f4310764d63a879f8452169a03081a9 100644 (file)
@@ -1049,6 +1049,28 @@ static const char *req_table_func(ap_expr_eval_ctx_t *ctx, const void *data,
     return apr_table_get(t, arg);
 }
 
+static const char *kb_func(ap_expr_eval_ctx_t *ctx, const void *data,
+                                  const char *arg)
+{
+    apr_off_t length;
+    apr_size_t len;
+    apr_status_t rv;
+    char *buf;
+
+    if (!ctx->r || !ctx->r->kept_body)
+        return "";
+
+    rv = apr_brigade_length(ctx->r->kept_body, 1, &length);
+    len = (apr_size_t)length;;
+    if (rv != APR_SUCCESS || len == 0)
+        return "";
+
+    buf = apr_palloc(ctx->r->pool, len);
+    apr_brigade_flatten(ctx->r->kept_body, buf, &len);
+    buf[len-1] = '\0'; /* ensure */
+    return (const char*)buf;
+}
+
 static const char *env_func(ap_expr_eval_ctx_t *ctx, const void *data,
                             const char *arg)
 {
@@ -1785,6 +1807,7 @@ static const struct expr_provider_single string_func_providers[] = {
     { unbase64_func,        "unbase64",       NULL, 0 },
     { sha1_func,            "sha1",           NULL, 0 },
     { md5_func,             "md5",            NULL, 0 },
+    { kb_func,             "kept_body",       NULL, 0 },
 #if APR_VERSION_AT_LEAST(1,6,0)
     { ldap_func,            "ldap",           NULL, 0 },
 #endif