]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http: smp_fetch_capture_header_* fetch captured headers
authorWilliam Lallemand <wlallemand@exceliance.fr>
Tue, 28 Jan 2014 17:14:25 +0000 (18:14 +0100)
committerWilly Tarreau <w@1wt.eu>
Tue, 28 Jan 2014 17:43:57 +0000 (18:43 +0100)
Allows you to fetch a captured header content with capture.res.hdr()
and capture.req.hdr().

doc/configuration.txt
src/proto_http.c

index 0fd73a4283010cf8faf51c1d50874fd61de0d1dc..68603bcd445b789be33a6c8b2edff2ee8331572b 100644 (file)
@@ -10456,6 +10456,16 @@ cookie([<name>]) : string (deprecated)
   ambiguously uses the direction based on the context where it is used.
   See also : "appsession".
 
+capture.req.hdr(<idx>) : string
+  This extracts the content of the header captured by the "capture request
+  header", idx is the position of the capture keyword in the configuration.
+  See also: "capture request header"
+
+capture.res.hdr(<idx>) : string
+  This extracts the content of the header captured by the "capture response
+  header", idx is the position of the capture keyword in the configuration.
+  See also: "capture response header"
+
 hdr([<name>[,<occ>]]) : string
   This is equivalent to req.hdr() when used on requests, and to res.hdr() when
   used on responses. Please refer to these respective fetches for more details.
index 95fb870eac40ac8ddb4137bea7254289b8c7b427..1484e13cc9953d1eac39606712d37b8af418cef3 100644 (file)
@@ -9646,6 +9646,58 @@ extract_cookie_value(char *hdr, const char *hdr_end,
        return NULL;
 }
 
+/* Fetch a captured HTTP request header. The index is the position of
+ * the "capture" option in the configuration file
+ */
+static int
+smp_fetch_capture_header_req(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
+                 const struct arg *args, struct sample *smp, const char *kw)
+{
+       struct proxy *fe = l4->fe;
+       struct http_txn *txn = l7;
+       int idx;
+
+       if (!args || args->type != ARGT_UINT)
+               return 0;
+
+       idx = args->data.uint;
+
+       if (idx > (fe->nb_req_cap - 1) || txn->req.cap == NULL || txn->req.cap[idx] == NULL)
+               return 0;
+
+       smp->type = SMP_T_CSTR;
+       smp->data.str.str = txn->req.cap[idx];
+       smp->data.str.len = strlen(txn->req.cap[idx]);
+
+       return 1;
+}
+
+/* Fetch a captured HTTP response header. The index is the position of
+ * the "capture" option in the configuration file
+ */
+static int
+smp_fetch_capture_header_res(struct proxy *px, struct session *l4, void *l7, unsigned int opt,
+                 const struct arg *args, struct sample *smp, const char *kw)
+{
+       struct proxy *fe = l4->fe;
+       struct http_txn *txn = l7;
+       int idx;
+
+       if (!args || args->type != ARGT_UINT)
+               return 0;
+
+       idx = args->data.uint;
+
+       if (idx > (fe->nb_rsp_cap - 1) || txn->rsp.cap == NULL || txn->rsp.cap[idx] == NULL)
+               return 0;
+
+       smp->type = SMP_T_CSTR;
+       smp->data.str.str = txn->rsp.cap[idx];
+       smp->data.str.len = strlen(txn->rsp.cap[idx]);
+
+       return 1;
+}
+
 /* Iterate over all cookies present in a message. The context is stored in
  * smp->ctx.a[0] for the in-header position, smp->ctx.a[1] for the
  * end-of-header-value, and smp->ctx.a[2] for the hdr_ctx. Depending on
@@ -10204,6 +10256,10 @@ static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
        { "base32",          smp_fetch_base32,         0,                NULL,    SMP_T_UINT, SMP_USE_HRQHV },
        { "base32+src",      smp_fetch_base32_src,     0,                NULL,    SMP_T_BIN,  SMP_USE_HRQHV },
 
+       /* capture are allocated and are permanent in the session */
+       { "capture.req.hdr", smp_fetch_capture_header_req, ARG1(1, UINT), NULL, SMP_T_CSTR, SMP_USE_HRQHP },
+       { "capture.res.hdr", smp_fetch_capture_header_res, ARG1(1, UINT), NULL, SMP_T_CSTR, SMP_USE_HRSHP },
+
        /* cookie is valid in both directions (eg: for "stick ...") but cook*
         * are only here to match the ACL's name, are request-only and are used
         * for ACL compatibility only.