blob: 338ced9f63da9d3c23f25a9bee343c01ac775afc [file] [log] [blame]
Willy Tarreau79e57332018-10-02 16:01:16 +02001/*
2 * HTTP samples fetching
3 *
4 * Copyright 2000-2018 Willy Tarreau <w@1wt.eu>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 */
12
13#include <sys/types.h>
14
15#include <ctype.h>
16#include <string.h>
17#include <time.h>
18
19#include <common/base64.h>
20#include <common/chunk.h>
21#include <common/compat.h>
22#include <common/config.h>
23#include <common/debug.h>
Willy Tarreauafba57a2018-12-11 13:44:24 +010024#include <common/h1.h>
Willy Tarreau79e57332018-10-02 16:01:16 +020025#include <common/http.h>
Willy Tarreaub96b77e2018-12-11 10:22:41 +010026#include <common/htx.h>
Willy Tarreau0108d902018-11-25 19:14:37 +010027#include <common/initcall.h>
Willy Tarreau79e57332018-10-02 16:01:16 +020028#include <common/memory.h>
29#include <common/standard.h>
30#include <common/version.h>
31
32#include <types/global.h>
33
34#include <proto/arg.h>
35#include <proto/auth.h>
Christopher Fauleteb2754b2019-07-16 14:49:01 +020036#include <proto/channel.h>
Willy Tarreau9a1efe12019-07-17 17:13:50 +020037#include <proto/connection.h>
Willy Tarreau79e57332018-10-02 16:01:16 +020038#include <proto/http_fetch.h>
Christopher Faulet53a899b2019-10-08 16:38:42 +020039#include <proto/h1_htx.h>
Christopher Fauletef453ed2018-10-24 21:39:27 +020040#include <proto/http_htx.h>
Willy Tarreau79e57332018-10-02 16:01:16 +020041#include <proto/log.h>
42#include <proto/obj_type.h>
Christopher Fauletfc9cfe42019-07-16 14:54:53 +020043#include <proto/http_ana.h>
Willy Tarreau79e57332018-10-02 16:01:16 +020044#include <proto/sample.h>
45#include <proto/stream.h>
46
47
48/* this struct is used between calls to smp_fetch_hdr() or smp_fetch_cookie() */
Christopher Fauletef453ed2018-10-24 21:39:27 +020049static THREAD_LOCAL struct http_hdr_ctx static_http_hdr_ctx;
Richard Russo458eafb2019-07-31 11:45:56 -070050/* this is used to convert raw connection buffers to htx */
51static THREAD_LOCAL struct buffer static_raw_htx_chunk;
52static THREAD_LOCAL char *static_raw_htx_buf;
Christopher Fauletef453ed2018-10-24 21:39:27 +020053
Christopher Faulet89dc4992019-04-17 12:02:59 +020054#define SMP_REQ_CHN(smp) (smp->strm ? &smp->strm->req : NULL)
55#define SMP_RES_CHN(smp) (smp->strm ? &smp->strm->res : NULL)
Willy Tarreau79e57332018-10-02 16:01:16 +020056
Richard Russo458eafb2019-07-31 11:45:56 -070057/* This function returns the static htx chunk, where raw connections get
58 * converted to HTX as needed for samplxsing.
59 */
60struct buffer *get_raw_htx_chunk(void)
61{
62 chunk_reset(&static_raw_htx_chunk);
63 return &static_raw_htx_chunk;
64}
65
66static int alloc_raw_htx_chunk_per_thread()
67{
68 static_raw_htx_buf = malloc(global.tune.bufsize);
69 if (!static_raw_htx_buf)
70 return 0;
71 chunk_init(&static_raw_htx_chunk, static_raw_htx_buf, global.tune.bufsize);
72 return 1;
73}
74
75static void free_raw_htx_chunk_per_thread()
76{
77 free(static_raw_htx_buf);
78 static_raw_htx_buf = NULL;
79}
80
81REGISTER_PER_THREAD_ALLOC(alloc_raw_htx_chunk_per_thread);
82REGISTER_PER_THREAD_FREE(free_raw_htx_chunk_per_thread);
83
Willy Tarreau79e57332018-10-02 16:01:16 +020084/*
85 * Returns the data from Authorization header. Function may be called more
86 * than once so data is stored in txn->auth_data. When no header is found
87 * or auth method is unknown auth_method is set to HTTP_AUTH_WRONG to avoid
88 * searching again for something we are unable to find anyway. However, if
89 * the result if valid, the cache is not reused because we would risk to
90 * have the credentials overwritten by another stream in parallel.
Willy Tarreaueae83722020-04-29 11:52:51 +020091 * The caller is responsible for passing a sample with a valid stream/txn,
92 * and a valid htx.
Willy Tarreau79e57332018-10-02 16:01:16 +020093 */
94
Christopher Fauletcd761952019-07-15 13:58:29 +020095static int get_http_auth(struct sample *smp, struct htx *htx)
Willy Tarreau79e57332018-10-02 16:01:16 +020096{
Christopher Faulet311c7ea2018-10-24 21:41:55 +020097 struct stream *s = smp->strm;
Willy Tarreau79e57332018-10-02 16:01:16 +020098 struct http_txn *txn = s->txn;
Christopher Faulet6d1dd462019-07-15 14:36:03 +020099 struct http_hdr_ctx ctx = { .blk = NULL };
100 struct ist hdr;
Willy Tarreau79e57332018-10-02 16:01:16 +0200101 struct buffer auth_method;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200102 char *p;
Willy Tarreau79e57332018-10-02 16:01:16 +0200103 int len;
104
105#ifdef DEBUG_AUTH
106 printf("Auth for stream %p: %d\n", s, txn->auth.method);
107#endif
Willy Tarreau79e57332018-10-02 16:01:16 +0200108 if (txn->auth.method == HTTP_AUTH_WRONG)
109 return 0;
110
111 txn->auth.method = HTTP_AUTH_WRONG;
112
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200113 if (txn->flags & TX_USE_PX_CONN)
114 hdr = ist("Proxy-Authorization");
115 else
116 hdr = ist("Authorization");
Willy Tarreau79e57332018-10-02 16:01:16 +0200117
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200118 ctx.blk = NULL;
119 if (!http_find_header(htx, hdr, &ctx, 0))
120 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200121
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200122 p = memchr(ctx.value.ptr, ' ', ctx.value.len);
123 len = p - ctx.value.ptr;
124 if (!p || len <= 0)
125 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200126
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200127 if (chunk_initlen(&auth_method, ctx.value.ptr, 0, len) != 1)
128 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200129
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200130 chunk_initlen(&txn->auth.method_data, p + 1, 0, ctx.value.len - len - 1);
Willy Tarreau79e57332018-10-02 16:01:16 +0200131
132 if (!strncasecmp("Basic", auth_method.area, auth_method.data)) {
133 struct buffer *http_auth = get_trash_chunk();
134
135 len = base64dec(txn->auth.method_data.area,
136 txn->auth.method_data.data,
137 http_auth->area, global.tune.bufsize - 1);
138
139 if (len < 0)
140 return 0;
141
142
143 http_auth->area[len] = '\0';
144
145 p = strchr(http_auth->area, ':');
146
147 if (!p)
148 return 0;
149
150 txn->auth.user = http_auth->area;
151 *p = '\0';
152 txn->auth.pass = p+1;
153
154 txn->auth.method = HTTP_AUTH_BASIC;
155 return 1;
156 }
157
158 return 0;
159}
160
161/* This function ensures that the prerequisites for an L7 fetch are ready,
162 * which means that a request or response is ready. If some data is missing,
163 * a parsing attempt is made. This is useful in TCP-based ACLs which are able
Christopher Faulet5ec8bcb2019-04-17 12:04:12 +0200164 * to extract data from L7. If <vol> is non-null during a prefetch, another
165 * test is made to ensure the required information is not gone.
Christopher Fauletef453ed2018-10-24 21:39:27 +0200166 *
167 * The function returns :
168 * NULL with SMP_F_MAY_CHANGE in the sample flags if some data is missing to
169 * decide whether or not an HTTP message is present ;
170 * NULL if the requested data cannot be fetched or if it is certain that
Willy Tarreaueae83722020-04-29 11:52:51 +0200171 * we'll never have any HTTP message there; this includes null strm or chn.
Christopher Fauletef453ed2018-10-24 21:39:27 +0200172 * The HTX message if ready
173 */
Christopher Faulet5ec8bcb2019-04-17 12:04:12 +0200174struct htx *smp_prefetch_htx(struct sample *smp, struct channel *chn, int vol)
Christopher Fauletef453ed2018-10-24 21:39:27 +0200175{
Christopher Fauletef453ed2018-10-24 21:39:27 +0200176 struct stream *s = smp->strm;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200177 struct http_txn *txn = NULL;
178 struct htx *htx = NULL;
Christopher Faulet89dc4992019-04-17 12:02:59 +0200179 struct http_msg *msg;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100180 struct htx_sl *sl;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200181
182 /* Note: it is possible that <s> is NULL when called before stream
183 * initialization (eg: tcp-request connection), so this function is the
184 * one responsible for guarding against this case for all HTTP users.
185 */
Christopher Faulet89dc4992019-04-17 12:02:59 +0200186 if (!s || !chn)
Christopher Fauletef453ed2018-10-24 21:39:27 +0200187 return NULL;
188
189 if (!s->txn) {
190 if (unlikely(!http_alloc_txn(s)))
191 return NULL; /* not enough memory */
192 http_init_txn(s);
193 txn = s->txn;
194 }
Christopher Faulet89dc4992019-04-17 12:02:59 +0200195 txn = s->txn;
196 msg = (!(chn->flags & CF_ISRESP) ? &txn->req : &txn->rsp);
197 smp->data.type = SMP_T_BOOL;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200198
Christopher Fauleteca88542019-04-03 10:12:42 +0200199 if (IS_HTX_STRM(s)) {
Christopher Faulet89dc4992019-04-17 12:02:59 +0200200 htx = htxbuf(&chn->buf);
Christopher Fauletef453ed2018-10-24 21:39:27 +0200201
Christopher Faulet89dc4992019-04-17 12:02:59 +0200202 if (msg->msg_state == HTTP_MSG_ERROR || (htx->flags & HTX_FL_PARSING_ERROR))
203 return NULL;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200204
Christopher Faulet89dc4992019-04-17 12:02:59 +0200205 if (msg->msg_state < HTTP_MSG_BODY) {
206 /* Analyse not yet started */
Christopher Faulet29f17582019-05-23 11:03:26 +0200207 if (htx_is_empty(htx) || htx->first == -1) {
Christopher Fauletef453ed2018-10-24 21:39:27 +0200208 /* Parsing is done by the mux, just wait */
209 smp->flags |= SMP_F_MAY_CHANGE;
210 return NULL;
211 }
212 }
Christopher Faulet297fbb42019-05-13 14:41:27 +0200213 sl = http_get_stline(htx);
Christopher Faulet5ec8bcb2019-04-17 12:04:12 +0200214 if (vol && !sl) {
Christopher Faulet89dc4992019-04-17 12:02:59 +0200215 /* The start-line was already forwarded, it is too late to fetch anything */
216 return NULL;
217 }
Christopher Fauletef453ed2018-10-24 21:39:27 +0200218 }
Christopher Fauleteca88542019-04-03 10:12:42 +0200219 else { /* RAW mode */
Christopher Faulet89dc4992019-04-17 12:02:59 +0200220 struct buffer *buf;
221 struct h1m h1m;
Christopher Faulete4ab11b2019-06-11 15:05:37 +0200222 struct http_hdr hdrs[global.tune.max_http_hdr];
Christopher Faulet89dc4992019-04-17 12:02:59 +0200223 union h1_sl h1sl;
224 unsigned int flags = HTX_FL_NONE;
225 int ret;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200226
Christopher Faulet89dc4992019-04-17 12:02:59 +0200227 /* no HTTP fetch on the response in TCP mode */
228 if (chn->flags & CF_ISRESP)
229 return NULL;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200230
Christopher Faulet89dc4992019-04-17 12:02:59 +0200231 /* Now we are working on the request only */
232 buf = &chn->buf;
233 if (b_head(buf) + b_data(buf) > b_wrap(buf))
234 b_slow_realign(buf, trash.area, 0);
Christopher Fauletef453ed2018-10-24 21:39:27 +0200235
Christopher Faulet89dc4992019-04-17 12:02:59 +0200236 h1m_init_req(&h1m);
237 ret = h1_headers_to_hdr_list(b_head(buf), b_stop(buf),
238 hdrs, sizeof(hdrs)/sizeof(hdrs[0]), &h1m, &h1sl);
239 if (ret <= 0) {
240 /* Invalid or too big*/
241 if (ret < 0 || channel_full(&s->req, global.tune.maxrewrite))
Christopher Fauletef453ed2018-10-24 21:39:27 +0200242 return NULL;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100243
Christopher Faulet89dc4992019-04-17 12:02:59 +0200244 /* wait for a full request */
245 smp->flags |= SMP_F_MAY_CHANGE;
246 return NULL;
247 }
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100248
Christopher Faulet89dc4992019-04-17 12:02:59 +0200249 /* OK we just got a valid HTTP mesage. We have to convert it
250 * into an HTX message.
251 */
252 if (unlikely(h1sl.rq.v.len == 0)) {
253 /* try to convert HTTP/0.9 requests to HTTP/1.0 */
254 if (h1sl.rq.meth != HTTP_METH_GET || !h1sl.rq.u.len)
Christopher Fauletef453ed2018-10-24 21:39:27 +0200255 return NULL;
Christopher Faulet89dc4992019-04-17 12:02:59 +0200256 h1sl.rq.v = ist("HTTP/1.0");
Christopher Fauletef453ed2018-10-24 21:39:27 +0200257 }
Christopher Faulet89dc4992019-04-17 12:02:59 +0200258
259 /* Set HTX start-line flags */
260 if (h1m.flags & H1_MF_VER_11)
261 flags |= HTX_SL_F_VER_11;
262 if (h1m.flags & H1_MF_XFER_ENC)
263 flags |= HTX_SL_F_XFER_ENC;
264 flags |= HTX_SL_F_XFER_LEN;
265 if (h1m.flags & H1_MF_CHNK)
266 flags |= HTX_SL_F_CHNK;
267 else if (h1m.flags & H1_MF_CLEN)
268 flags |= HTX_SL_F_CLEN;
269
Richard Russo458eafb2019-07-31 11:45:56 -0700270 htx = htx_from_buf(get_raw_htx_chunk());
Christopher Faulet89dc4992019-04-17 12:02:59 +0200271 sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, h1sl.rq.m, h1sl.rq.u, h1sl.rq.v);
272 if (!sl || !htx_add_all_headers(htx, hdrs))
Christopher Fauletef453ed2018-10-24 21:39:27 +0200273 return NULL;
Willy Tarreauce9bbf52019-05-13 08:32:31 +0200274 sl->info.req.meth = h1sl.rq.meth;
Christopher Faulet89dc4992019-04-17 12:02:59 +0200275 }
276
277 /* OK we just got a valid HTTP message. If not already done by
278 * HTTP analyzers, we have some minor preparation to perform so
279 * that further checks can rely on HTTP tests.
280 */
281 if (sl && msg->msg_state < HTTP_MSG_BODY) {
282 if (!(chn->flags & CF_ISRESP)) {
283 txn->meth = sl->info.req.meth;
284 if (txn->meth == HTTP_METH_GET || txn->meth == HTTP_METH_HEAD)
285 s->flags |= SF_REDIRECTABLE;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200286 }
Christopher Faulet89dc4992019-04-17 12:02:59 +0200287 else
288 txn->status = sl->info.res.status;
289 if (sl->flags & HTX_SL_F_VER_11)
290 msg->flags |= HTTP_MSGF_VER_11;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200291 }
292
293 /* everything's OK */
294 smp->data.u.sint = 1;
295 return htx;
296}
297
Willy Tarreau79e57332018-10-02 16:01:16 +0200298/* This function fetches the method of current HTTP request and stores
299 * it in the global pattern struct as a chunk. There are two possibilities :
300 * - if the method is known (not HTTP_METH_OTHER), its identifier is stored
301 * in <len> and <ptr> is NULL ;
302 * - if the method is unknown (HTTP_METH_OTHER), <ptr> points to the text and
303 * <len> to its length.
304 * This is intended to be used with pat_match_meth() only.
305 */
306static int smp_fetch_meth(const struct arg *args, struct sample *smp, const char *kw, void *private)
307{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200308 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200309 struct htx *htx = smp_prefetch_htx(smp, chn, 0);
Willy Tarreau79e57332018-10-02 16:01:16 +0200310 struct http_txn *txn;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200311 int meth;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200312
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200313 if (!htx)
314 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200315
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200316 txn = smp->strm->txn;
317 meth = txn->meth;
318 smp->data.type = SMP_T_METH;
319 smp->data.u.meth.meth = meth;
320 if (meth == HTTP_METH_OTHER) {
321 struct htx_sl *sl;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200322
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200323 if ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) {
324 /* ensure the indexes are not affected */
325 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200326 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200327 sl = http_get_stline(htx);
328 smp->flags |= SMP_F_CONST;
329 smp->data.u.meth.str.area = HTX_SL_REQ_MPTR(sl);
330 smp->data.u.meth.str.data = HTX_SL_REQ_MLEN(sl);
Willy Tarreau79e57332018-10-02 16:01:16 +0200331 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200332 smp->flags |= SMP_F_VOL_1ST;
Willy Tarreau79e57332018-10-02 16:01:16 +0200333 return 1;
334}
335
336static int smp_fetch_rqver(const struct arg *args, struct sample *smp, const char *kw, void *private)
337{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200338 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200339 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
340 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +0200341 char *ptr;
342 int len;
343
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200344 if (!htx)
345 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200346
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200347 sl = http_get_stline(htx);
348 len = HTX_SL_REQ_VLEN(sl);
349 ptr = HTX_SL_REQ_VPTR(sl);
Willy Tarreau79e57332018-10-02 16:01:16 +0200350
351 while ((len-- > 0) && (*ptr++ != '/'));
352 if (len <= 0)
353 return 0;
354
355 smp->data.type = SMP_T_STR;
356 smp->data.u.str.area = ptr;
357 smp->data.u.str.data = len;
358
359 smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
360 return 1;
361}
362
363static int smp_fetch_stver(const struct arg *args, struct sample *smp, const char *kw, void *private)
364{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200365 struct channel *chn = SMP_RES_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200366 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
367 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +0200368 char *ptr;
369 int len;
370
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200371 if (!htx)
372 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200373
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200374 sl = http_get_stline(htx);
375 len = HTX_SL_RES_VLEN(sl);
376 ptr = HTX_SL_RES_VPTR(sl);
Willy Tarreau79e57332018-10-02 16:01:16 +0200377
378 while ((len-- > 0) && (*ptr++ != '/'));
379 if (len <= 0)
380 return 0;
381
382 smp->data.type = SMP_T_STR;
383 smp->data.u.str.area = ptr;
384 smp->data.u.str.data = len;
385
386 smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
387 return 1;
388}
389
390/* 3. Check on Status Code. We manipulate integers here. */
391static int smp_fetch_stcode(const struct arg *args, struct sample *smp, const char *kw, void *private)
392{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200393 struct channel *chn = SMP_RES_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200394 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
395 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +0200396 char *ptr;
397 int len;
398
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200399 if (!htx)
400 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200401
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200402 sl = http_get_stline(htx);
403 len = HTX_SL_RES_CLEN(sl);
404 ptr = HTX_SL_RES_CPTR(sl);
Willy Tarreau79e57332018-10-02 16:01:16 +0200405
406 smp->data.type = SMP_T_SINT;
407 smp->data.u.sint = __strl2ui(ptr, len);
408 smp->flags = SMP_F_VOL_1ST;
409 return 1;
410}
411
412static int smp_fetch_uniqueid(const struct arg *args, struct sample *smp, const char *kw, void *private)
413{
Tim Duesterhusa17e6622020-03-05 20:19:02 +0100414 struct ist unique_id;
Tim Duesterhus2825b4b2020-02-28 15:13:34 +0100415
Willy Tarreau79e57332018-10-02 16:01:16 +0200416 if (LIST_ISEMPTY(&smp->sess->fe->format_unique_id))
417 return 0;
418
Willy Tarreaua1062a42020-04-29 11:50:38 +0200419 if (!smp->strm)
420 return 0;
421
Tim Duesterhusa17e6622020-03-05 20:19:02 +0100422 unique_id = stream_generate_unique_id(smp->strm, &smp->sess->fe->format_unique_id);
423 if (!isttest(unique_id))
Tim Duesterhus2825b4b2020-02-28 15:13:34 +0100424 return 0;
425
Tim Duesterhusa17e6622020-03-05 20:19:02 +0100426 smp->data.u.str.area = smp->strm->unique_id.ptr;
427 smp->data.u.str.data = smp->strm->unique_id.len;
Tim Duesterhus2825b4b2020-02-28 15:13:34 +0100428 smp->data.type = SMP_T_STR;
Willy Tarreau79e57332018-10-02 16:01:16 +0200429 smp->flags = SMP_F_CONST;
430 return 1;
431}
432
433/* Returns a string block containing all headers including the
Joseph Herlant942eea32018-11-15 13:57:22 -0800434 * empty line which separes headers from the body. This is useful
435 * for some headers analysis.
Willy Tarreau79e57332018-10-02 16:01:16 +0200436 */
437static int smp_fetch_hdrs(const struct arg *args, struct sample *smp, const char *kw, void *private)
438{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200439 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200440 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
441 struct buffer *temp;
442 int32_t pos;
Willy Tarreau79e57332018-10-02 16:01:16 +0200443
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200444 if (!htx)
445 return 0;
446 temp = get_trash_chunk();
447 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
448 struct htx_blk *blk = htx_get_blk(htx, pos);
449 enum htx_blk_type type = htx_get_blk_type(blk);
Willy Tarreau79e57332018-10-02 16:01:16 +0200450
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200451 if (type == HTX_BLK_HDR) {
452 struct ist n = htx_get_blk_name(htx, blk);
453 struct ist v = htx_get_blk_value(htx, blk);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200454
Christopher Faulet53a899b2019-10-08 16:38:42 +0200455 if (!h1_format_htx_hdr(n, v, temp))
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200456 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200457 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200458 else if (type == HTX_BLK_EOH) {
459 if (!chunk_memcat(temp, "\r\n", 2))
460 return 0;
461 break;
462 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200463 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200464 smp->data.type = SMP_T_STR;
465 smp->data.u.str = *temp;
Willy Tarreau79e57332018-10-02 16:01:16 +0200466 return 1;
467}
468
469/* Returns the header request in a length/value encoded format.
470 * This is useful for exchanges with the SPOE.
471 *
472 * A "length value" is a multibyte code encoding numbers. It uses the
473 * SPOE format. The encoding is the following:
474 *
475 * Each couple "header name" / "header value" is composed
476 * like this:
477 * "length value" "header name bytes"
478 * "length value" "header value bytes"
479 * When the last header is reached, the header name and the header
480 * value are empty. Their length are 0
481 */
482static int smp_fetch_hdrs_bin(const struct arg *args, struct sample *smp, const char *kw, void *private)
483{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200484 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200485 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200486 struct buffer *temp;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200487 char *p, *end;
488 int32_t pos;
489 int ret;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200490
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200491 if (!htx)
492 return 0;
493 temp = get_trash_chunk();
494 p = temp->area;
495 end = temp->area + temp->size;
496 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
497 struct htx_blk *blk = htx_get_blk(htx, pos);
498 enum htx_blk_type type = htx_get_blk_type(blk);
499 struct ist n, v;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200500
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200501 if (type == HTX_BLK_HDR) {
502 n = htx_get_blk_name(htx,blk);
503 v = htx_get_blk_value(htx, blk);
Willy Tarreau79e57332018-10-02 16:01:16 +0200504
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200505 /* encode the header name. */
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200506 ret = encode_varint(n.len, &p, end);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200507 if (ret == -1)
508 return 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200509 if (p + n.len > end)
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200510 return 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200511 memcpy(p, n.ptr, n.len);
512 p += n.len;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200513
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200514 /* encode the header value. */
515 ret = encode_varint(v.len, &p, end);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200516 if (ret == -1)
517 return 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200518 if (p + v.len > end)
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200519 return 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200520 memcpy(p, v.ptr, v.len);
521 p += v.len;
Willy Tarreau79e57332018-10-02 16:01:16 +0200522
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200523 }
524 else if (type == HTX_BLK_EOH) {
525 /* encode the end of the header list with empty
526 * header name and header value.
527 */
528 ret = encode_varint(0, &p, end);
529 if (ret == -1)
530 return 0;
531 ret = encode_varint(0, &p, end);
532 if (ret == -1)
533 return 0;
534 break;
535 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200536 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200537
538 /* Initialise sample data which will be filled. */
539 smp->data.type = SMP_T_BIN;
540 smp->data.u.str.area = temp->area;
541 smp->data.u.str.data = p - temp->area;
542 smp->data.u.str.size = temp->size;
Willy Tarreau79e57332018-10-02 16:01:16 +0200543 return 1;
544}
545
546/* returns the longest available part of the body. This requires that the body
547 * has been waited for using http-buffer-request.
548 */
549static int smp_fetch_body(const struct arg *args, struct sample *smp, const char *kw, void *private)
550{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200551 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200552 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
Willy Tarreau79e57332018-10-02 16:01:16 +0200553 struct buffer *temp;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200554 int32_t pos;
Willy Tarreau79e57332018-10-02 16:01:16 +0200555
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200556 if (!htx)
557 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200558
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200559 temp = get_trash_chunk();
560 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
561 struct htx_blk *blk = htx_get_blk(htx, pos);
562 enum htx_blk_type type = htx_get_blk_type(blk);
Willy Tarreau79e57332018-10-02 16:01:16 +0200563
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200564 if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
565 break;
566 if (type == HTX_BLK_DATA) {
Christopher Faulet53a899b2019-10-08 16:38:42 +0200567 if (!h1_format_htx_data(htx_get_blk_value(htx, blk), temp, 0))
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200568 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200569 }
Willy Tarreau79e57332018-10-02 16:01:16 +0200570 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200571
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200572 smp->data.type = SMP_T_BIN;
573 smp->data.u.str = *temp;
574 smp->flags = SMP_F_VOL_TEST;
Willy Tarreau79e57332018-10-02 16:01:16 +0200575 return 1;
576}
577
578
579/* returns the available length of the body. This requires that the body
580 * has been waited for using http-buffer-request.
581 */
582static int smp_fetch_body_len(const struct arg *args, struct sample *smp, const char *kw, void *private)
583{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200584 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200585 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
586 int32_t pos;
587 unsigned long long len = 0;
Christopher Fauletc16317d2018-12-12 14:11:22 +0100588
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200589 if (!htx)
590 return 0;
Christopher Fauletc16317d2018-12-12 14:11:22 +0100591
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200592 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
593 struct htx_blk *blk = htx_get_blk(htx, pos);
594 enum htx_blk_type type = htx_get_blk_type(blk);
Christopher Fauletc16317d2018-12-12 14:11:22 +0100595
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200596 if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
597 break;
598 if (type == HTX_BLK_DATA)
599 len += htx_get_blksz(blk);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200600 }
Willy Tarreau79e57332018-10-02 16:01:16 +0200601
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200602 smp->data.type = SMP_T_SINT;
603 smp->data.u.sint = len;
604 smp->flags = SMP_F_VOL_TEST;
Willy Tarreau79e57332018-10-02 16:01:16 +0200605 return 1;
606}
607
608
609/* returns the advertised length of the body, or the advertised size of the
610 * chunks available in the buffer. This requires that the body has been waited
611 * for using http-buffer-request.
612 */
613static int smp_fetch_body_size(const struct arg *args, struct sample *smp, const char *kw, void *private)
614{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200615 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200616 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
617 int32_t pos;
618 unsigned long long len = 0;
Christopher Faulet89dc4992019-04-17 12:02:59 +0200619
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200620 if (!htx)
621 return 0;
Christopher Fauletc16317d2018-12-12 14:11:22 +0100622
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200623 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
624 struct htx_blk *blk = htx_get_blk(htx, pos);
625 enum htx_blk_type type = htx_get_blk_type(blk);
Christopher Fauletc16317d2018-12-12 14:11:22 +0100626
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200627 if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
628 break;
629 if (type == HTX_BLK_DATA)
630 len += htx_get_blksz(blk);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200631 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200632 if (htx->extra != ULLONG_MAX)
633 len += htx->extra;
Willy Tarreau79e57332018-10-02 16:01:16 +0200634
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200635 smp->data.type = SMP_T_SINT;
636 smp->data.u.sint = len;
637 smp->flags = SMP_F_VOL_TEST;
Willy Tarreau79e57332018-10-02 16:01:16 +0200638 return 1;
639}
640
641
642/* 4. Check on URL/URI. A pointer to the URI is stored. */
643static int smp_fetch_url(const struct arg *args, struct sample *smp, const char *kw, void *private)
644{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200645 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200646 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
647 struct htx_sl *sl;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200648
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200649 if (!htx)
650 return 0;
651 sl = http_get_stline(htx);
652 smp->data.type = SMP_T_STR;
653 smp->data.u.str.area = HTX_SL_REQ_UPTR(sl);
654 smp->data.u.str.data = HTX_SL_REQ_ULEN(sl);
655 smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
Willy Tarreau79e57332018-10-02 16:01:16 +0200656 return 1;
657}
658
659static int smp_fetch_url_ip(const struct arg *args, struct sample *smp, const char *kw, void *private)
660{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200661 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200662 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
663 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +0200664 struct sockaddr_storage addr;
665
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200666 if (!htx)
667 return 0;
668 sl = http_get_stline(htx);
669 url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL);
Willy Tarreau79e57332018-10-02 16:01:16 +0200670
Willy Tarreau79e57332018-10-02 16:01:16 +0200671 if (((struct sockaddr_in *)&addr)->sin_family != AF_INET)
672 return 0;
673
674 smp->data.type = SMP_T_IPV4;
675 smp->data.u.ipv4 = ((struct sockaddr_in *)&addr)->sin_addr;
676 smp->flags = 0;
677 return 1;
678}
679
680static int smp_fetch_url_port(const struct arg *args, struct sample *smp, const char *kw, void *private)
681{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200682 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200683 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
684 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +0200685 struct sockaddr_storage addr;
686
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200687 if (!htx)
688 return 0;
689 sl = http_get_stline(htx);
690 url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200691
Willy Tarreau79e57332018-10-02 16:01:16 +0200692 if (((struct sockaddr_in *)&addr)->sin_family != AF_INET)
693 return 0;
694
695 smp->data.type = SMP_T_SINT;
696 smp->data.u.sint = ntohs(((struct sockaddr_in *)&addr)->sin_port);
697 smp->flags = 0;
698 return 1;
699}
700
701/* Fetch an HTTP header. A pointer to the beginning of the value is returned.
702 * Accepts an optional argument of type string containing the header field name,
703 * and an optional argument of type signed or unsigned integer to request an
704 * explicit occurrence of the header. Note that in the event of a missing name,
705 * headers are considered from the first one. It does not stop on commas and
706 * returns full lines instead (useful for User-Agent or Date for example).
707 */
708static int smp_fetch_fhdr(const struct arg *args, struct sample *smp, const char *kw, void *private)
709{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200710 /* possible keywords: req.fhdr, res.fhdr */
711 struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200712 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
713 struct http_hdr_ctx *ctx = smp->ctx.a[0];
714 struct ist name;
Willy Tarreau79e57332018-10-02 16:01:16 +0200715 int occ = 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200716
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200717 if (!ctx) {
718 /* first call */
719 ctx = &static_http_hdr_ctx;
720 ctx->blk = NULL;
721 smp->ctx.a[0] = ctx;
722 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200723
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200724 if (args) {
725 if (args[0].type != ARGT_STR)
Willy Tarreau79e57332018-10-02 16:01:16 +0200726 return 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200727 name.ptr = args[0].data.str.area;
728 name.len = args[0].data.str.data;
Willy Tarreau79e57332018-10-02 16:01:16 +0200729
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200730 if (args[1].type == ARGT_SINT)
731 occ = args[1].data.sint;
Willy Tarreau79e57332018-10-02 16:01:16 +0200732 }
733
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200734 if (!htx)
735 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200736
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200737 if (ctx && !(smp->flags & SMP_F_NOT_LAST))
738 /* search for header from the beginning */
739 ctx->blk = NULL;
Willy Tarreau79e57332018-10-02 16:01:16 +0200740
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200741 if (!occ && !(smp->opt & SMP_OPT_ITERATE))
742 /* no explicit occurrence and single fetch => last header by default */
743 occ = -1;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200744
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200745 if (!occ)
746 /* prepare to report multiple occurrences for ACL fetches */
747 smp->flags |= SMP_F_NOT_LAST;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200748
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200749 smp->data.type = SMP_T_STR;
750 smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST;
751 if (http_get_htx_fhdr(htx, name, occ, ctx, &smp->data.u.str.area, &smp->data.u.str.data))
752 return 1;
Willy Tarreau79e57332018-10-02 16:01:16 +0200753 smp->flags &= ~SMP_F_NOT_LAST;
754 return 0;
755}
756
757/* 6. Check on HTTP header count. The number of occurrences is returned.
758 * Accepts exactly 1 argument of type string. It does not stop on commas and
759 * returns full lines instead (useful for User-Agent or Date for example).
760 */
761static int smp_fetch_fhdr_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
762{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200763 /* possible keywords: req.fhdr_cnt, res.fhdr_cnt */
764 struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200765 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
766 struct http_hdr_ctx ctx;
767 struct ist name;
Willy Tarreau79e57332018-10-02 16:01:16 +0200768 int cnt;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200769
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200770 if (!htx)
771 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200772
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200773 if (args && args->type == ARGT_STR) {
774 name.ptr = args->data.str.area;
775 name.len = args->data.str.data;
776 } else {
777 name.ptr = NULL;
778 name.len = 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200779 }
Willy Tarreau79e57332018-10-02 16:01:16 +0200780
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200781 ctx.blk = NULL;
782 cnt = 0;
783 while (http_find_header(htx, name, &ctx, 1))
784 cnt++;
Willy Tarreau79e57332018-10-02 16:01:16 +0200785 smp->data.type = SMP_T_SINT;
786 smp->data.u.sint = cnt;
787 smp->flags = SMP_F_VOL_HDR;
788 return 1;
789}
790
791static int smp_fetch_hdr_names(const struct arg *args, struct sample *smp, const char *kw, void *private)
792{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200793 /* possible keywords: req.hdr_names, res.hdr_names */
794 struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200795 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
Willy Tarreau79e57332018-10-02 16:01:16 +0200796 struct buffer *temp;
797 char del = ',';
798
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200799 int32_t pos;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200800
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200801 if (!htx)
802 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200803
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200804 if (args && args->type == ARGT_STR)
805 del = *args[0].data.str.area;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200806
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200807 temp = get_trash_chunk();
808 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
809 struct htx_blk *blk = htx_get_blk(htx, pos);
810 enum htx_blk_type type = htx_get_blk_type(blk);
811 struct ist n;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200812
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200813 if (type == HTX_BLK_EOH)
814 break;
815 if (type != HTX_BLK_HDR)
816 continue;
817 n = htx_get_blk_name(htx, blk);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200818
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200819 if (temp->data)
820 temp->area[temp->data++] = del;
821 chunk_memcat(temp, n.ptr, n.len);
Willy Tarreau79e57332018-10-02 16:01:16 +0200822 }
823
824 smp->data.type = SMP_T_STR;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200825 smp->data.u.str = *temp;
Willy Tarreau79e57332018-10-02 16:01:16 +0200826 smp->flags = SMP_F_VOL_HDR;
827 return 1;
828}
829
830/* Fetch an HTTP header. A pointer to the beginning of the value is returned.
831 * Accepts an optional argument of type string containing the header field name,
832 * and an optional argument of type signed or unsigned integer to request an
833 * explicit occurrence of the header. Note that in the event of a missing name,
834 * headers are considered from the first one.
835 */
836static int smp_fetch_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private)
837{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200838 /* possible keywords: req.hdr / hdr, res.hdr / shdr */
839 struct channel *chn = ((kw[0] == 'h' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200840 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
841 struct http_hdr_ctx *ctx = smp->ctx.a[0];
842 struct ist name;
Willy Tarreau79e57332018-10-02 16:01:16 +0200843 int occ = 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200844
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200845 if (!ctx) {
846 /* first call */
847 ctx = &static_http_hdr_ctx;
848 ctx->blk = NULL;
849 smp->ctx.a[0] = ctx;
850 }
Willy Tarreau79e57332018-10-02 16:01:16 +0200851
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200852 if (args) {
853 if (args[0].type != ARGT_STR)
Willy Tarreau79e57332018-10-02 16:01:16 +0200854 return 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200855 name.ptr = args[0].data.str.area;
856 name.len = args[0].data.str.data;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200857
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200858 if (args[1].type == ARGT_SINT)
859 occ = args[1].data.sint;
Willy Tarreau79e57332018-10-02 16:01:16 +0200860 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200861
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200862 if (!htx)
863 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200864
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200865 if (ctx && !(smp->flags & SMP_F_NOT_LAST))
866 /* search for header from the beginning */
867 ctx->blk = NULL;
Willy Tarreau79e57332018-10-02 16:01:16 +0200868
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200869 if (!occ && !(smp->opt & SMP_OPT_ITERATE))
870 /* no explicit occurrence and single fetch => last header by default */
871 occ = -1;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200872
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200873 if (!occ)
874 /* prepare to report multiple occurrences for ACL fetches */
875 smp->flags |= SMP_F_NOT_LAST;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200876
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200877 smp->data.type = SMP_T_STR;
878 smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST;
879 if (http_get_htx_hdr(htx, name, occ, ctx, &smp->data.u.str.area, &smp->data.u.str.data))
880 return 1;
Willy Tarreau79e57332018-10-02 16:01:16 +0200881
882 smp->flags &= ~SMP_F_NOT_LAST;
883 return 0;
884}
885
Christopher Fauletc1f40dd2019-05-16 10:07:30 +0200886/* Same than smp_fetch_hdr() but only relies on the sample direction to choose
887 * the right channel. So instead of duplicating the code, we just change the
888 * keyword and then fallback on smp_fetch_hdr().
889 */
890static int smp_fetch_chn_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private)
891{
892 kw = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ ? "req.hdr" : "res.hdr");
893 return smp_fetch_hdr(args, smp, kw, private);
894}
895
Willy Tarreau79e57332018-10-02 16:01:16 +0200896/* 6. Check on HTTP header count. The number of occurrences is returned.
897 * Accepts exactly 1 argument of type string.
898 */
899static int smp_fetch_hdr_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
900{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200901 /* possible keywords: req.hdr_cnt / hdr_cnt, res.hdr_cnt / shdr_cnt */
902 struct channel *chn = ((kw[0] == 'h' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200903 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
904 struct http_hdr_ctx ctx;
905 struct ist name;
Willy Tarreau79e57332018-10-02 16:01:16 +0200906 int cnt;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200907
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200908 if (!htx)
909 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200910
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200911 if (args && args->type == ARGT_STR) {
912 name.ptr = args->data.str.area;
913 name.len = args->data.str.data;
914 } else {
915 name.ptr = NULL;
916 name.len = 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200917 }
Willy Tarreau79e57332018-10-02 16:01:16 +0200918
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200919 ctx.blk = NULL;
920 cnt = 0;
921 while (http_find_header(htx, name, &ctx, 0))
922 cnt++;
Willy Tarreau79e57332018-10-02 16:01:16 +0200923
924 smp->data.type = SMP_T_SINT;
925 smp->data.u.sint = cnt;
926 smp->flags = SMP_F_VOL_HDR;
927 return 1;
928}
929
930/* Fetch an HTTP header's integer value. The integer value is returned. It
931 * takes a mandatory argument of type string and an optional one of type int
932 * to designate a specific occurrence. It returns an unsigned integer, which
933 * may or may not be appropriate for everything.
934 */
935static int smp_fetch_hdr_val(const struct arg *args, struct sample *smp, const char *kw, void *private)
936{
937 int ret = smp_fetch_hdr(args, smp, kw, private);
938
939 if (ret > 0) {
940 smp->data.type = SMP_T_SINT;
941 smp->data.u.sint = strl2ic(smp->data.u.str.area,
942 smp->data.u.str.data);
943 }
944
945 return ret;
946}
947
948/* Fetch an HTTP header's IP value. takes a mandatory argument of type string
949 * and an optional one of type int to designate a specific occurrence.
950 * It returns an IPv4 or IPv6 address.
951 */
952static int smp_fetch_hdr_ip(const struct arg *args, struct sample *smp, const char *kw, void *private)
953{
954 int ret;
955
956 while ((ret = smp_fetch_hdr(args, smp, kw, private)) > 0) {
957 if (url2ipv4((char *) smp->data.u.str.area, &smp->data.u.ipv4)) {
958 smp->data.type = SMP_T_IPV4;
959 break;
960 } else {
961 struct buffer *temp = get_trash_chunk();
962 if (smp->data.u.str.data < temp->size - 1) {
963 memcpy(temp->area, smp->data.u.str.area,
964 smp->data.u.str.data);
965 temp->area[smp->data.u.str.data] = '\0';
966 if (inet_pton(AF_INET6, temp->area, &smp->data.u.ipv6)) {
967 smp->data.type = SMP_T_IPV6;
968 break;
969 }
970 }
971 }
972
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200973 /* if the header doesn't match an IP address, fetch next one */
974 if (!(smp->flags & SMP_F_NOT_LAST))
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200975 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200976 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200977 return ret;
978}
Willy Tarreau79e57332018-10-02 16:01:16 +0200979
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200980/* 8. Check on URI PATH. A pointer to the PATH is stored. The path starts at
981 * the first '/' after the possible hostname, and ends before the possible '?'.
982 */
983static int smp_fetch_path(const struct arg *args, struct sample *smp, const char *kw, void *private)
984{
985 struct channel *chn = SMP_REQ_CHN(smp);
986 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
987 struct htx_sl *sl;
988 struct ist path;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200989
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200990 if (!htx)
991 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200992
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200993 sl = http_get_stline(htx);
Jerome Magnin4fb196c2020-02-21 10:49:12 +0100994 path = iststop(http_get_path(htx_sl_req_uri(sl)), '?');
Tim Duesterhused526372020-03-05 17:56:33 +0100995 if (!isttest(path))
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200996 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200997
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200998 /* OK, we got the '/' ! */
999 smp->data.type = SMP_T_STR;
1000 smp->data.u.str.area = path.ptr;
Jerome Magnin4fb196c2020-02-21 10:49:12 +01001001 smp->data.u.str.data = path.len;
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001002 smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
Willy Tarreau79e57332018-10-02 16:01:16 +02001003 return 1;
1004}
1005
1006/* This produces a concatenation of the first occurrence of the Host header
1007 * followed by the path component if it begins with a slash ('/'). This means
1008 * that '*' will not be added, resulting in exactly the first Host entry.
1009 * If no Host header is found, then the path is returned as-is. The returned
1010 * value is stored in the trash so it does not need to be marked constant.
1011 * The returned sample is of type string.
1012 */
1013static int smp_fetch_base(const struct arg *args, struct sample *smp, const char *kw, void *private)
1014{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001015 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001016 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1017 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +02001018 struct buffer *temp;
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001019 struct http_hdr_ctx ctx;
1020 struct ist path;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001021
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001022 if (!htx)
1023 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001024
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001025 ctx.blk = NULL;
1026 if (!http_find_header(htx, ist("Host"), &ctx, 0) || !ctx.value.len)
1027 return smp_fetch_path(args, smp, kw, private);
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001028
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001029 /* OK we have the header value in ctx.value */
1030 temp = get_trash_chunk();
1031 chunk_memcat(temp, ctx.value.ptr, ctx.value.len);
Willy Tarreau79e57332018-10-02 16:01:16 +02001032
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001033 /* now retrieve the path */
1034 sl = http_get_stline(htx);
1035 path = http_get_path(htx_sl_req_uri(sl));
Tim Duesterhused526372020-03-05 17:56:33 +01001036 if (isttest(path)) {
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001037 size_t len;
Willy Tarreau79e57332018-10-02 16:01:16 +02001038
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001039 for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++)
1040 ;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001041
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001042 if (len && *(path.ptr) == '/')
1043 chunk_memcat(temp, path.ptr, len);
Willy Tarreau79e57332018-10-02 16:01:16 +02001044 }
1045
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001046 smp->data.type = SMP_T_STR;
1047 smp->data.u.str = *temp;
Willy Tarreau79e57332018-10-02 16:01:16 +02001048 smp->flags = SMP_F_VOL_1ST;
1049 return 1;
1050}
1051
1052/* This produces a 32-bit hash of the concatenation of the first occurrence of
1053 * the Host header followed by the path component if it begins with a slash ('/').
1054 * This means that '*' will not be added, resulting in exactly the first Host
1055 * entry. If no Host header is found, then the path is used. The resulting value
1056 * is hashed using the path hash followed by a full avalanche hash and provides a
1057 * 32-bit integer value. This fetch is useful for tracking per-path activity on
1058 * high-traffic sites without having to store whole paths.
1059 */
1060static int smp_fetch_base32(const struct arg *args, struct sample *smp, const char *kw, void *private)
1061{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001062 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001063 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1064 struct htx_sl *sl;
1065 struct http_hdr_ctx ctx;
1066 struct ist path;
Willy Tarreau79e57332018-10-02 16:01:16 +02001067 unsigned int hash = 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001068
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001069 if (!htx)
1070 return 0;
Dragan Dosen8861e1c2019-02-12 19:50:31 +01001071
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001072 ctx.blk = NULL;
1073 if (http_find_header(htx, ist("Host"), &ctx, 0)) {
1074 /* OK we have the header value in ctx.value */
1075 while (ctx.value.len--)
1076 hash = *(ctx.value.ptr++) + (hash << 6) + (hash << 16) - hash;
Willy Tarreau79e57332018-10-02 16:01:16 +02001077 }
1078
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001079 /* now retrieve the path */
1080 sl = http_get_stline(htx);
1081 path = http_get_path(htx_sl_req_uri(sl));
Tim Duesterhused526372020-03-05 17:56:33 +01001082 if (isttest(path)) {
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001083 size_t len;
Willy Tarreau79e57332018-10-02 16:01:16 +02001084
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001085 for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++)
1086 ;
Willy Tarreau79e57332018-10-02 16:01:16 +02001087
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001088 if (len && *(path.ptr) == '/') {
1089 while (len--)
1090 hash = *(path.ptr++) + (hash << 6) + (hash << 16) - hash;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001091 }
Willy Tarreau79e57332018-10-02 16:01:16 +02001092 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001093
Willy Tarreau79e57332018-10-02 16:01:16 +02001094 hash = full_hash(hash);
1095
1096 smp->data.type = SMP_T_SINT;
1097 smp->data.u.sint = hash;
1098 smp->flags = SMP_F_VOL_1ST;
1099 return 1;
1100}
1101
1102/* This concatenates the source address with the 32-bit hash of the Host and
1103 * path as returned by smp_fetch_base32(). The idea is to have per-source and
1104 * per-path counters. The result is a binary block from 8 to 20 bytes depending
1105 * on the source address length. The path hash is stored before the address so
1106 * that in environments where IPv6 is insignificant, truncating the output to
1107 * 8 bytes would still work.
1108 */
1109static int smp_fetch_base32_src(const struct arg *args, struct sample *smp, const char *kw, void *private)
1110{
1111 struct buffer *temp;
1112 struct connection *cli_conn = objt_conn(smp->sess->origin);
1113
Willy Tarreaucd7ca792019-07-17 16:57:03 +02001114 if (!cli_conn || !conn_get_src(cli_conn))
Willy Tarreau79e57332018-10-02 16:01:16 +02001115 return 0;
1116
1117 if (!smp_fetch_base32(args, smp, kw, private))
1118 return 0;
1119
1120 temp = get_trash_chunk();
1121 *(unsigned int *) temp->area = htonl(smp->data.u.sint);
1122 temp->data += sizeof(unsigned int);
1123
Willy Tarreau9a1efe12019-07-17 17:13:50 +02001124 switch (cli_conn->src->ss_family) {
Willy Tarreau79e57332018-10-02 16:01:16 +02001125 case AF_INET:
1126 memcpy(temp->area + temp->data,
Willy Tarreau9a1efe12019-07-17 17:13:50 +02001127 &((struct sockaddr_in *)cli_conn->src)->sin_addr,
Willy Tarreau79e57332018-10-02 16:01:16 +02001128 4);
1129 temp->data += 4;
1130 break;
1131 case AF_INET6:
1132 memcpy(temp->area + temp->data,
Willy Tarreau9a1efe12019-07-17 17:13:50 +02001133 &((struct sockaddr_in6 *)cli_conn->src)->sin6_addr,
Willy Tarreau79e57332018-10-02 16:01:16 +02001134 16);
1135 temp->data += 16;
1136 break;
1137 default:
1138 return 0;
1139 }
1140
1141 smp->data.u.str = *temp;
1142 smp->data.type = SMP_T_BIN;
1143 return 1;
1144}
1145
1146/* Extracts the query string, which comes after the question mark '?'. If no
1147 * question mark is found, nothing is returned. Otherwise it returns a sample
1148 * of type string carrying the whole query string.
1149 */
1150static int smp_fetch_query(const struct arg *args, struct sample *smp, const char *kw, void *private)
1151{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001152 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001153 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1154 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +02001155 char *ptr, *end;
1156
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001157 if (!htx)
1158 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001159
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001160 sl = http_get_stline(htx);
1161 ptr = HTX_SL_REQ_UPTR(sl);
1162 end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
Willy Tarreau79e57332018-10-02 16:01:16 +02001163
1164 /* look up the '?' */
1165 do {
1166 if (ptr == end)
1167 return 0;
1168 } while (*ptr++ != '?');
1169
1170 smp->data.type = SMP_T_STR;
1171 smp->data.u.str.area = ptr;
1172 smp->data.u.str.data = end - ptr;
1173 smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
1174 return 1;
1175}
1176
1177static int smp_fetch_proto_http(const struct arg *args, struct sample *smp, const char *kw, void *private)
1178{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001179 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001180 struct htx *htx = smp_prefetch_htx(smp, chn, 0);
Willy Tarreau79e57332018-10-02 16:01:16 +02001181
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001182 if (!htx)
1183 return 0;
1184 smp->data.type = SMP_T_BOOL;
Willy Tarreau79e57332018-10-02 16:01:16 +02001185 smp->data.u.sint = 1;
1186 return 1;
1187}
1188
1189/* return a valid test if the current request is the first one on the connection */
1190static int smp_fetch_http_first_req(const struct arg *args, struct sample *smp, const char *kw, void *private)
1191{
Willy Tarreau79512b62020-04-29 11:52:13 +02001192 if (!smp->strm)
1193 return 0;
1194
Willy Tarreau79e57332018-10-02 16:01:16 +02001195 smp->data.type = SMP_T_BOOL;
1196 smp->data.u.sint = !(smp->strm->txn->flags & TX_NOT_FIRST);
1197 return 1;
1198}
1199
Christopher Fauleta4063562019-08-02 11:51:37 +02001200/* Fetch the authentication method if there is an Authorization header. It
1201 * relies on get_http_auth()
1202 */
1203static int smp_fetch_http_auth_type(const struct arg *args, struct sample *smp, const char *kw, void *private)
1204{
1205 struct channel *chn = SMP_REQ_CHN(smp);
1206 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1207 struct http_txn *txn;
1208
1209 if (!htx)
1210 return 0;
1211
1212 txn = smp->strm->txn;
1213 if (!get_http_auth(smp, htx))
1214 return 0;
1215
1216 switch (txn->auth.method) {
1217 case HTTP_AUTH_BASIC:
1218 smp->data.u.str.area = "Basic";
1219 smp->data.u.str.data = 5;
1220 break;
1221 case HTTP_AUTH_DIGEST:
1222 /* Unexpected because not supported */
1223 smp->data.u.str.area = "Digest";
1224 smp->data.u.str.data = 6;
1225 break;
1226 default:
1227 return 0;
1228 }
1229
1230 smp->data.type = SMP_T_STR;
1231 smp->flags = SMP_F_CONST;
1232 return 1;
1233}
1234
1235/* Fetch the user supplied if there is an Authorization header. It relies on
1236 * get_http_auth()
1237 */
1238static int smp_fetch_http_auth_user(const struct arg *args, struct sample *smp, const char *kw, void *private)
1239{
1240 struct channel *chn = SMP_REQ_CHN(smp);
1241 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1242 struct http_txn *txn;
1243
1244 if (!htx)
1245 return 0;
1246
1247 txn = smp->strm->txn;
1248 if (!get_http_auth(smp, htx))
1249 return 0;
1250
1251 smp->data.type = SMP_T_STR;
1252 smp->data.u.str.area = txn->auth.user;
1253 smp->data.u.str.data = strlen(txn->auth.user);
1254 smp->flags = SMP_F_CONST;
1255 return 1;
1256}
1257
1258/* Fetch the password supplied if there is an Authorization header. It relies on
1259 * get_http_auth()
1260 */
1261static int smp_fetch_http_auth_pass(const struct arg *args, struct sample *smp, const char *kw, void *private)
1262{
1263 struct channel *chn = SMP_REQ_CHN(smp);
1264 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1265 struct http_txn *txn;
1266
1267 if (!htx)
1268 return 0;
1269
1270 txn = smp->strm->txn;
1271 if (!get_http_auth(smp, htx))
1272 return 0;
1273
1274 smp->data.type = SMP_T_STR;
1275 smp->data.u.str.area = txn->auth.pass;
1276 smp->data.u.str.data = strlen(txn->auth.pass);
1277 smp->flags = SMP_F_CONST;
1278 return 1;
1279}
1280
Willy Tarreau79e57332018-10-02 16:01:16 +02001281/* Accepts exactly 1 argument of type userlist */
1282static int smp_fetch_http_auth(const struct arg *args, struct sample *smp, const char *kw, void *private)
1283{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001284 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001285 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
Willy Tarreau79e57332018-10-02 16:01:16 +02001286
1287 if (!args || args->type != ARGT_USR)
1288 return 0;
1289
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001290 if (!htx)
1291 return 0;
1292 if (!get_http_auth(smp, htx))
1293 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001294
1295 smp->data.type = SMP_T_BOOL;
1296 smp->data.u.sint = check_user(args->data.usr, smp->strm->txn->auth.user,
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001297 smp->strm->txn->auth.pass);
Willy Tarreau79e57332018-10-02 16:01:16 +02001298 return 1;
1299}
1300
1301/* Accepts exactly 1 argument of type userlist */
1302static int smp_fetch_http_auth_grp(const struct arg *args, struct sample *smp, const char *kw, void *private)
1303{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001304 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001305 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
Christopher Faulet89dc4992019-04-17 12:02:59 +02001306
Willy Tarreau79e57332018-10-02 16:01:16 +02001307 if (!args || args->type != ARGT_USR)
1308 return 0;
1309
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001310 if (!htx)
1311 return 0;
1312 if (!get_http_auth(smp, htx))
1313 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001314
Willy Tarreau79e57332018-10-02 16:01:16 +02001315 /* if the user does not belong to the userlist or has a wrong password,
1316 * report that it unconditionally does not match. Otherwise we return
1317 * a string containing the username.
1318 */
1319 if (!check_user(args->data.usr, smp->strm->txn->auth.user,
1320 smp->strm->txn->auth.pass))
1321 return 0;
1322
1323 /* pat_match_auth() will need the user list */
1324 smp->ctx.a[0] = args->data.usr;
1325
1326 smp->data.type = SMP_T_STR;
1327 smp->flags = SMP_F_CONST;
1328 smp->data.u.str.area = smp->strm->txn->auth.user;
1329 smp->data.u.str.data = strlen(smp->strm->txn->auth.user);
1330
1331 return 1;
1332}
1333
1334/* Fetch a captured HTTP request header. The index is the position of
1335 * the "capture" option in the configuration file
1336 */
1337static int smp_fetch_capture_req_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private)
1338{
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001339 struct proxy *fe;
Willy Tarreau79e57332018-10-02 16:01:16 +02001340 int idx;
1341
1342 if (!args || args->type != ARGT_SINT)
1343 return 0;
1344
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001345 if (!smp->strm)
1346 return 0;
1347
1348 fe = strm_fe(smp->strm);
Willy Tarreau79e57332018-10-02 16:01:16 +02001349 idx = args->data.sint;
1350
1351 if (idx > (fe->nb_req_cap - 1) || smp->strm->req_cap == NULL || smp->strm->req_cap[idx] == NULL)
1352 return 0;
1353
1354 smp->data.type = SMP_T_STR;
1355 smp->flags |= SMP_F_CONST;
1356 smp->data.u.str.area = smp->strm->req_cap[idx];
1357 smp->data.u.str.data = strlen(smp->strm->req_cap[idx]);
1358
1359 return 1;
1360}
1361
1362/* Fetch a captured HTTP response header. The index is the position of
1363 * the "capture" option in the configuration file
1364 */
1365static int smp_fetch_capture_res_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private)
1366{
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001367 struct proxy *fe;
Willy Tarreau79e57332018-10-02 16:01:16 +02001368 int idx;
1369
1370 if (!args || args->type != ARGT_SINT)
1371 return 0;
1372
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001373 if (!smp->strm)
1374 return 0;
1375
1376 fe = strm_fe(smp->strm);
Willy Tarreau79e57332018-10-02 16:01:16 +02001377 idx = args->data.sint;
1378
1379 if (idx > (fe->nb_rsp_cap - 1) || smp->strm->res_cap == NULL || smp->strm->res_cap[idx] == NULL)
1380 return 0;
1381
1382 smp->data.type = SMP_T_STR;
1383 smp->flags |= SMP_F_CONST;
1384 smp->data.u.str.area = smp->strm->res_cap[idx];
1385 smp->data.u.str.data = strlen(smp->strm->res_cap[idx]);
1386
1387 return 1;
1388}
1389
1390/* Extracts the METHOD in the HTTP request, the txn->uri should be filled before the call */
1391static int smp_fetch_capture_req_method(const struct arg *args, struct sample *smp, const char *kw, void *private)
1392{
1393 struct buffer *temp;
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001394 struct http_txn *txn;
Willy Tarreau79e57332018-10-02 16:01:16 +02001395 char *ptr;
1396
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001397 if (!smp->strm)
1398 return 0;
1399
1400 txn = smp->strm->txn;
Willy Tarreau79e57332018-10-02 16:01:16 +02001401 if (!txn || !txn->uri)
1402 return 0;
1403
1404 ptr = txn->uri;
1405
1406 while (*ptr != ' ' && *ptr != '\0') /* find first space */
1407 ptr++;
1408
1409 temp = get_trash_chunk();
1410 temp->area = txn->uri;
1411 temp->data = ptr - txn->uri;
1412 smp->data.u.str = *temp;
1413 smp->data.type = SMP_T_STR;
1414 smp->flags = SMP_F_CONST;
1415
1416 return 1;
1417
1418}
1419
1420/* Extracts the path in the HTTP request, the txn->uri should be filled before the call */
1421static int smp_fetch_capture_req_uri(const struct arg *args, struct sample *smp, const char *kw, void *private)
1422{
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001423 struct http_txn *txn;
Willy Tarreau79e57332018-10-02 16:01:16 +02001424 struct ist path;
1425 const char *ptr;
1426
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001427 if (!smp->strm)
1428 return 0;
1429
1430 txn = smp->strm->txn;
Willy Tarreau79e57332018-10-02 16:01:16 +02001431 if (!txn || !txn->uri)
1432 return 0;
1433
1434 ptr = txn->uri;
1435
1436 while (*ptr != ' ' && *ptr != '\0') /* find first space */
1437 ptr++;
1438
1439 if (!*ptr)
1440 return 0;
1441
Christopher Faulet78337bb2018-11-15 14:35:18 +01001442 /* skip the first space and find space after URI */
1443 path = ist2(++ptr, 0);
1444 while (*ptr != ' ' && *ptr != '\0')
1445 ptr++;
1446 path.len = ptr - path.ptr;
Willy Tarreau79e57332018-10-02 16:01:16 +02001447
Christopher Faulet78337bb2018-11-15 14:35:18 +01001448 path = http_get_path(path);
Tim Duesterhused526372020-03-05 17:56:33 +01001449 if (!isttest(path))
Willy Tarreau79e57332018-10-02 16:01:16 +02001450 return 0;
1451
1452 smp->data.u.str.area = path.ptr;
1453 smp->data.u.str.data = path.len;
1454 smp->data.type = SMP_T_STR;
1455 smp->flags = SMP_F_CONST;
1456
1457 return 1;
1458}
1459
1460/* Retrieves the HTTP version from the request (either 1.0 or 1.1) and emits it
1461 * as a string (either "HTTP/1.0" or "HTTP/1.1").
1462 */
1463static int smp_fetch_capture_req_ver(const struct arg *args, struct sample *smp, const char *kw, void *private)
1464{
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001465 struct http_txn *txn;
1466
1467 if (!smp->strm)
1468 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001469
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001470 txn = smp->strm->txn;
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001471 if (!txn || txn->req.msg_state >= HTTP_MSG_BODY)
Willy Tarreau79e57332018-10-02 16:01:16 +02001472 return 0;
1473
1474 if (txn->req.flags & HTTP_MSGF_VER_11)
1475 smp->data.u.str.area = "HTTP/1.1";
1476 else
1477 smp->data.u.str.area = "HTTP/1.0";
1478
1479 smp->data.u.str.data = 8;
1480 smp->data.type = SMP_T_STR;
1481 smp->flags = SMP_F_CONST;
1482 return 1;
1483
1484}
1485
1486/* Retrieves the HTTP version from the response (either 1.0 or 1.1) and emits it
1487 * as a string (either "HTTP/1.0" or "HTTP/1.1").
1488 */
1489static int smp_fetch_capture_res_ver(const struct arg *args, struct sample *smp, const char *kw, void *private)
1490{
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001491 struct http_txn *txn;
1492
1493 if (!smp->strm)
1494 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001495
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001496 txn = smp->strm->txn;
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001497 if (!txn || txn->rsp.msg_state >= HTTP_MSG_BODY)
Willy Tarreau79e57332018-10-02 16:01:16 +02001498 return 0;
1499
1500 if (txn->rsp.flags & HTTP_MSGF_VER_11)
1501 smp->data.u.str.area = "HTTP/1.1";
1502 else
1503 smp->data.u.str.area = "HTTP/1.0";
1504
1505 smp->data.u.str.data = 8;
1506 smp->data.type = SMP_T_STR;
1507 smp->flags = SMP_F_CONST;
1508 return 1;
1509
1510}
1511
1512/* Iterate over all cookies present in a message. The context is stored in
1513 * smp->ctx.a[0] for the in-header position, smp->ctx.a[1] for the
1514 * end-of-header-value, and smp->ctx.a[2] for the hdr_ctx. Depending on
1515 * the direction, multiple cookies may be parsed on the same line or not.
1516 * The cookie name is in args and the name length in args->data.str.len.
1517 * Accepts exactly 1 argument of type string. If the input options indicate
1518 * that no iterating is desired, then only last value is fetched if any.
1519 * The returned sample is of type CSTR. Can be used to parse cookies in other
1520 * files.
1521 */
1522static int smp_fetch_cookie(const struct arg *args, struct sample *smp, const char *kw, void *private)
1523{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001524 /* possible keywords: req.cookie / cookie / cook, res.cookie / scook / set-cookie */
1525 struct channel *chn = ((kw[0] == 'c' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001526 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1527 struct http_hdr_ctx *ctx = smp->ctx.a[2];
1528 struct ist hdr;
Willy Tarreau79e57332018-10-02 16:01:16 +02001529 int occ = 0;
1530 int found = 0;
1531
1532 if (!args || args->type != ARGT_STR)
1533 return 0;
1534
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001535 if (!ctx) {
1536 /* first call */
1537 ctx = &static_http_hdr_ctx;
1538 ctx->blk = NULL;
1539 smp->ctx.a[2] = ctx;
1540 }
Willy Tarreau79e57332018-10-02 16:01:16 +02001541
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001542 if (!htx)
1543 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001544
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001545 hdr = (!(chn->flags & CF_ISRESP) ? ist("Cookie") : ist("Set-Cookie"));
Willy Tarreau79e57332018-10-02 16:01:16 +02001546
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001547 if (!occ && !(smp->opt & SMP_OPT_ITERATE))
1548 /* no explicit occurrence and single fetch => last cookie by default */
1549 occ = -1;
Willy Tarreau79e57332018-10-02 16:01:16 +02001550
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001551 /* OK so basically here, either we want only one value and it's the
1552 * last one, or we want to iterate over all of them and we fetch the
1553 * next one.
1554 */
Willy Tarreau79e57332018-10-02 16:01:16 +02001555
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001556 if (!(smp->flags & SMP_F_NOT_LAST)) {
1557 /* search for the header from the beginning, we must first initialize
1558 * the search parameters.
Willy Tarreau79e57332018-10-02 16:01:16 +02001559 */
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001560 smp->ctx.a[0] = NULL;
1561 ctx->blk = NULL;
Willy Tarreau79e57332018-10-02 16:01:16 +02001562 }
Willy Tarreau79e57332018-10-02 16:01:16 +02001563
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001564 smp->flags |= SMP_F_VOL_HDR;
1565 while (1) {
1566 /* Note: smp->ctx.a[0] == NULL every time we need to fetch a new header */
1567 if (!smp->ctx.a[0]) {
1568 if (!http_find_header(htx, hdr, ctx, 0))
1569 goto out;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001570
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001571 if (ctx->value.len < args->data.str.data + 1)
1572 continue;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001573
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001574 smp->ctx.a[0] = ctx->value.ptr;
1575 smp->ctx.a[1] = smp->ctx.a[0] + ctx->value.len;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001576 }
1577
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001578 smp->data.type = SMP_T_STR;
1579 smp->flags |= SMP_F_CONST;
1580 smp->ctx.a[0] = http_extract_cookie_value(smp->ctx.a[0], smp->ctx.a[1],
1581 args->data.str.area, args->data.str.data,
1582 (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ,
1583 &smp->data.u.str.area,
1584 &smp->data.u.str.data);
1585 if (smp->ctx.a[0]) {
1586 found = 1;
1587 if (occ >= 0) {
1588 /* one value was returned into smp->data.u.str.{str,len} */
1589 smp->flags |= SMP_F_NOT_LAST;
1590 return 1;
Willy Tarreau79e57332018-10-02 16:01:16 +02001591 }
1592 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001593 /* if we're looking for last occurrence, let's loop */
Willy Tarreau79e57332018-10-02 16:01:16 +02001594 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001595
Willy Tarreau79e57332018-10-02 16:01:16 +02001596 /* all cookie headers and values were scanned. If we're looking for the
1597 * last occurrence, we may return it now.
1598 */
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001599 out:
Willy Tarreau79e57332018-10-02 16:01:16 +02001600 smp->flags &= ~SMP_F_NOT_LAST;
1601 return found;
1602}
1603
Christopher Fauletc1f40dd2019-05-16 10:07:30 +02001604/* Same than smp_fetch_cookie() but only relies on the sample direction to
1605 * choose the right channel. So instead of duplicating the code, we just change
1606 * the keyword and then fallback on smp_fetch_cookie().
1607 */
1608static int smp_fetch_chn_cookie(const struct arg *args, struct sample *smp, const char *kw, void *private)
1609{
1610 kw = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ ? "req.cook" : "res.cook");
1611 return smp_fetch_cookie(args, smp, kw, private);
1612}
1613
Willy Tarreau79e57332018-10-02 16:01:16 +02001614/* Iterate over all cookies present in a request to count how many occurrences
1615 * match the name in args and args->data.str.len. If <multi> is non-null, then
1616 * multiple cookies may be parsed on the same line. The returned sample is of
1617 * type UINT. Accepts exactly 1 argument of type string.
1618 */
1619static int smp_fetch_cookie_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
1620{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001621 /* possible keywords: req.cook_cnt / cook_cnt, res.cook_cnt / scook_cnt */
1622 struct channel *chn = ((kw[0] == 'c' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001623 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1624 struct http_hdr_ctx ctx;
1625 struct ist hdr;
Willy Tarreau79e57332018-10-02 16:01:16 +02001626 char *val_beg, *val_end;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001627 int cnt;
Willy Tarreau79e57332018-10-02 16:01:16 +02001628
1629 if (!args || args->type != ARGT_STR)
1630 return 0;
1631
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001632 if (!htx)
1633 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001634
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001635 hdr = (!(chn->flags & CF_ISRESP) ? ist("Cookie") : ist("Set-Cookie"));
Willy Tarreau79e57332018-10-02 16:01:16 +02001636
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001637 val_end = val_beg = NULL;
1638 ctx.blk = NULL;
1639 cnt = 0;
1640 while (1) {
1641 /* Note: val_beg == NULL every time we need to fetch a new header */
1642 if (!val_beg) {
1643 if (!http_find_header(htx, hdr, &ctx, 0))
1644 break;
Willy Tarreau79e57332018-10-02 16:01:16 +02001645
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001646 if (ctx.value.len < args->data.str.data + 1)
1647 continue;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001648
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001649 val_beg = ctx.value.ptr;
1650 val_end = val_beg + ctx.value.len;
Willy Tarreau79e57332018-10-02 16:01:16 +02001651 }
1652
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001653 smp->data.type = SMP_T_STR;
1654 smp->flags |= SMP_F_CONST;
1655 while ((val_beg = http_extract_cookie_value(val_beg, val_end,
1656 args->data.str.area, args->data.str.data,
1657 (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ,
1658 &smp->data.u.str.area,
1659 &smp->data.u.str.data))) {
1660 cnt++;
Willy Tarreau79e57332018-10-02 16:01:16 +02001661 }
1662 }
1663
1664 smp->data.type = SMP_T_SINT;
1665 smp->data.u.sint = cnt;
1666 smp->flags |= SMP_F_VOL_HDR;
1667 return 1;
1668}
1669
1670/* Fetch an cookie's integer value. The integer value is returned. It
1671 * takes a mandatory argument of type string. It relies on smp_fetch_cookie().
1672 */
1673static int smp_fetch_cookie_val(const struct arg *args, struct sample *smp, const char *kw, void *private)
1674{
1675 int ret = smp_fetch_cookie(args, smp, kw, private);
1676
1677 if (ret > 0) {
1678 smp->data.type = SMP_T_SINT;
1679 smp->data.u.sint = strl2ic(smp->data.u.str.area,
1680 smp->data.u.str.data);
1681 }
1682
1683 return ret;
1684}
1685
1686/************************************************************************/
1687/* The code below is dedicated to sample fetches */
1688/************************************************************************/
1689
1690/* This scans a URL-encoded query string. It takes an optionally wrapping
1691 * string whose first contigous chunk has its beginning in ctx->a[0] and end
1692 * in ctx->a[1], and the optional second part in (ctx->a[2]..ctx->a[3]). The
1693 * pointers are updated for next iteration before leaving.
1694 */
1695static int smp_fetch_param(char delim, const char *name, int name_len, const struct arg *args, struct sample *smp, const char *kw, void *private)
1696{
1697 const char *vstart, *vend;
1698 struct buffer *temp;
1699 const char **chunks = (const char **)smp->ctx.a;
1700
1701 if (!http_find_next_url_param(chunks, name, name_len,
1702 &vstart, &vend, delim))
1703 return 0;
1704
1705 /* Create sample. If the value is contiguous, return the pointer as CONST,
1706 * if the value is wrapped, copy-it in a buffer.
1707 */
1708 smp->data.type = SMP_T_STR;
1709 if (chunks[2] &&
1710 vstart >= chunks[0] && vstart <= chunks[1] &&
1711 vend >= chunks[2] && vend <= chunks[3]) {
1712 /* Wrapped case. */
1713 temp = get_trash_chunk();
1714 memcpy(temp->area, vstart, chunks[1] - vstart);
1715 memcpy(temp->area + ( chunks[1] - vstart ), chunks[2],
1716 vend - chunks[2]);
1717 smp->data.u.str.area = temp->area;
1718 smp->data.u.str.data = ( chunks[1] - vstart ) + ( vend - chunks[2] );
1719 } else {
1720 /* Contiguous case. */
1721 smp->data.u.str.area = (char *)vstart;
1722 smp->data.u.str.data = vend - vstart;
1723 smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
1724 }
1725
1726 /* Update context, check wrapping. */
1727 chunks[0] = vend;
1728 if (chunks[2] && vend >= chunks[2] && vend <= chunks[3]) {
1729 chunks[1] = chunks[3];
1730 chunks[2] = NULL;
1731 }
1732
1733 if (chunks[0] < chunks[1])
1734 smp->flags |= SMP_F_NOT_LAST;
1735
1736 return 1;
1737}
1738
1739/* This function iterates over each parameter of the query string. It uses
1740 * ctx->a[0] and ctx->a[1] to store the beginning and end of the current
1741 * parameter. Since it uses smp_fetch_param(), ctx->a[2..3] are both NULL.
1742 * An optional parameter name is passed in args[0], otherwise any parameter is
1743 * considered. It supports an optional delimiter argument for the beginning of
1744 * the string in args[1], which defaults to "?".
1745 */
1746static int smp_fetch_url_param(const struct arg *args, struct sample *smp, const char *kw, void *private)
1747{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001748 struct channel *chn = SMP_REQ_CHN(smp);
Willy Tarreau79e57332018-10-02 16:01:16 +02001749 char delim = '?';
1750 const char *name;
1751 int name_len;
1752
1753 if (!args ||
1754 (args[0].type && args[0].type != ARGT_STR) ||
1755 (args[1].type && args[1].type != ARGT_STR))
1756 return 0;
1757
1758 name = "";
1759 name_len = 0;
1760 if (args->type == ARGT_STR) {
1761 name = args->data.str.area;
1762 name_len = args->data.str.data;
1763 }
1764
1765 if (args[1].type)
1766 delim = *args[1].data.str.area;
1767
1768 if (!smp->ctx.a[0]) { // first call, find the query string
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001769 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1770 struct htx_sl *sl;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001771
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001772 if (!htx)
1773 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001774
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001775 sl = http_get_stline(htx);
1776 smp->ctx.a[0] = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), delim);
1777 if (!smp->ctx.a[0])
1778 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001779
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001780 smp->ctx.a[1] = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
Willy Tarreau79e57332018-10-02 16:01:16 +02001781
1782 /* Assume that the context is filled with NULL pointer
1783 * before the first call.
1784 * smp->ctx.a[2] = NULL;
1785 * smp->ctx.a[3] = NULL;
1786 */
1787 }
1788
1789 return smp_fetch_param(delim, name, name_len, args, smp, kw, private);
1790}
1791
1792/* This function iterates over each parameter of the body. This requires
1793 * that the body has been waited for using http-buffer-request. It uses
1794 * ctx->a[0] and ctx->a[1] to store the beginning and end of the first
1795 * contigous part of the body, and optionally ctx->a[2..3] to reference the
1796 * optional second part if the body wraps at the end of the buffer. An optional
1797 * parameter name is passed in args[0], otherwise any parameter is considered.
1798 */
1799static int smp_fetch_body_param(const struct arg *args, struct sample *smp, const char *kw, void *private)
1800{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001801 struct channel *chn = SMP_REQ_CHN(smp);
Willy Tarreau79e57332018-10-02 16:01:16 +02001802 const char *name;
1803 int name_len;
1804
1805 if (!args || (args[0].type && args[0].type != ARGT_STR))
1806 return 0;
1807
1808 name = "";
1809 name_len = 0;
1810 if (args[0].type == ARGT_STR) {
1811 name = args[0].data.str.area;
1812 name_len = args[0].data.str.data;
1813 }
1814
1815 if (!smp->ctx.a[0]) { // first call, find the query string
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001816 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1817 struct buffer *temp;
1818 int32_t pos;
Willy Tarreau79e57332018-10-02 16:01:16 +02001819
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001820 if (!htx)
1821 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001822
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001823 temp = get_trash_chunk();
1824 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
1825 struct htx_blk *blk = htx_get_blk(htx, pos);
1826 enum htx_blk_type type = htx_get_blk_type(blk);
Willy Tarreau79e57332018-10-02 16:01:16 +02001827
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001828 if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
1829 break;
1830 if (type == HTX_BLK_DATA) {
Christopher Faulet53a899b2019-10-08 16:38:42 +02001831 if (!h1_format_htx_data(htx_get_blk_value(htx, blk), temp, 0))
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001832 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001833 }
Willy Tarreau79e57332018-10-02 16:01:16 +02001834 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001835
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001836 smp->ctx.a[0] = temp->area;
1837 smp->ctx.a[1] = temp->area + temp->data;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001838
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001839 /* Assume that the context is filled with NULL pointer
1840 * before the first call.
1841 * smp->ctx.a[2] = NULL;
1842 * smp->ctx.a[3] = NULL;
1843 */
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001844
Willy Tarreau79e57332018-10-02 16:01:16 +02001845 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001846
Willy Tarreau79e57332018-10-02 16:01:16 +02001847 return smp_fetch_param('&', name, name_len, args, smp, kw, private);
1848}
1849
1850/* Return the signed integer value for the specified url parameter (see url_param
1851 * above).
1852 */
1853static int smp_fetch_url_param_val(const struct arg *args, struct sample *smp, const char *kw, void *private)
1854{
1855 int ret = smp_fetch_url_param(args, smp, kw, private);
1856
1857 if (ret > 0) {
1858 smp->data.type = SMP_T_SINT;
1859 smp->data.u.sint = strl2ic(smp->data.u.str.area,
1860 smp->data.u.str.data);
1861 }
1862
1863 return ret;
1864}
1865
1866/* This produces a 32-bit hash of the concatenation of the first occurrence of
1867 * the Host header followed by the path component if it begins with a slash ('/').
1868 * This means that '*' will not be added, resulting in exactly the first Host
1869 * entry. If no Host header is found, then the path is used. The resulting value
1870 * is hashed using the url hash followed by a full avalanche hash and provides a
1871 * 32-bit integer value. This fetch is useful for tracking per-URL activity on
1872 * high-traffic sites without having to store whole paths.
1873 * this differs from the base32 functions in that it includes the url parameters
1874 * as well as the path
1875 */
1876static int smp_fetch_url32(const struct arg *args, struct sample *smp, const char *kw, void *private)
1877{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001878 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001879 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1880 struct http_hdr_ctx ctx;
1881 struct htx_sl *sl;
1882 struct ist path;
Willy Tarreau79e57332018-10-02 16:01:16 +02001883 unsigned int hash = 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001884
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001885 if (!htx)
1886 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001887
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001888 ctx.blk = NULL;
1889 if (http_find_header(htx, ist("Host"), &ctx, 1)) {
1890 /* OK we have the header value in ctx.value */
1891 while (ctx.value.len--)
1892 hash = *(ctx.value.ptr++) + (hash << 6) + (hash << 16) - hash;
Willy Tarreau79e57332018-10-02 16:01:16 +02001893 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001894
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001895 /* now retrieve the path */
1896 sl = http_get_stline(htx);
1897 path = http_get_path(htx_sl_req_uri(sl));
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001898 if (path.len && *(path.ptr) == '/') {
1899 while (path.len--)
1900 hash = *(path.ptr++) + (hash << 6) + (hash << 16) - hash;
Willy Tarreau79e57332018-10-02 16:01:16 +02001901 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001902
Willy Tarreau79e57332018-10-02 16:01:16 +02001903 hash = full_hash(hash);
1904
1905 smp->data.type = SMP_T_SINT;
1906 smp->data.u.sint = hash;
1907 smp->flags = SMP_F_VOL_1ST;
1908 return 1;
1909}
1910
1911/* This concatenates the source address with the 32-bit hash of the Host and
1912 * URL as returned by smp_fetch_base32(). The idea is to have per-source and
1913 * per-url counters. The result is a binary block from 8 to 20 bytes depending
1914 * on the source address length. The URL hash is stored before the address so
1915 * that in environments where IPv6 is insignificant, truncating the output to
1916 * 8 bytes would still work.
1917 */
1918static int smp_fetch_url32_src(const struct arg *args, struct sample *smp, const char *kw, void *private)
1919{
1920 struct buffer *temp;
1921 struct connection *cli_conn = objt_conn(smp->sess->origin);
1922
Willy Tarreaucd7ca792019-07-17 16:57:03 +02001923 if (!cli_conn || !conn_get_src(cli_conn))
Willy Tarreau79e57332018-10-02 16:01:16 +02001924 return 0;
1925
1926 if (!smp_fetch_url32(args, smp, kw, private))
1927 return 0;
1928
1929 temp = get_trash_chunk();
1930 *(unsigned int *) temp->area = htonl(smp->data.u.sint);
1931 temp->data += sizeof(unsigned int);
1932
Willy Tarreau9a1efe12019-07-17 17:13:50 +02001933 switch (cli_conn->src->ss_family) {
Willy Tarreau79e57332018-10-02 16:01:16 +02001934 case AF_INET:
1935 memcpy(temp->area + temp->data,
Willy Tarreau9a1efe12019-07-17 17:13:50 +02001936 &((struct sockaddr_in *)cli_conn->src)->sin_addr,
Willy Tarreau79e57332018-10-02 16:01:16 +02001937 4);
1938 temp->data += 4;
1939 break;
1940 case AF_INET6:
1941 memcpy(temp->area + temp->data,
Willy Tarreau9a1efe12019-07-17 17:13:50 +02001942 &((struct sockaddr_in6 *)cli_conn->src)->sin6_addr,
Willy Tarreau79e57332018-10-02 16:01:16 +02001943 16);
1944 temp->data += 16;
1945 break;
1946 default:
1947 return 0;
1948 }
1949
1950 smp->data.u.str = *temp;
1951 smp->data.type = SMP_T_BIN;
1952 return 1;
1953}
1954
1955/************************************************************************/
1956/* Other utility functions */
1957/************************************************************************/
1958
1959/* This function is used to validate the arguments passed to any "hdr" fetch
1960 * keyword. These keywords support an optional positive or negative occurrence
1961 * number. We must ensure that the number is greater than -MAX_HDR_HISTORY. It
1962 * is assumed that the types are already the correct ones. Returns 0 on error,
1963 * non-zero if OK. If <err> is not NULL, it will be filled with a pointer to an
1964 * error message in case of error, that the caller is responsible for freeing.
1965 * The initial location must either be freeable or NULL.
1966 * Note: this function's pointer is checked from Lua.
1967 */
1968int val_hdr(struct arg *arg, char **err_msg)
1969{
1970 if (arg && arg[1].type == ARGT_SINT && arg[1].data.sint < -MAX_HDR_HISTORY) {
1971 memprintf(err_msg, "header occurrence must be >= %d", -MAX_HDR_HISTORY);
1972 return 0;
1973 }
1974 return 1;
1975}
1976
1977/************************************************************************/
1978/* All supported sample fetch keywords must be declared here. */
1979/************************************************************************/
1980
1981/* Note: must not be declared <const> as its list will be overwritten */
1982static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
1983 { "base", smp_fetch_base, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
1984 { "base32", smp_fetch_base32, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV },
1985 { "base32+src", smp_fetch_base32_src, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV },
1986
1987 /* capture are allocated and are permanent in the stream */
1988 { "capture.req.hdr", smp_fetch_capture_req_hdr, ARG1(1,SINT), NULL, SMP_T_STR, SMP_USE_HRQHP },
1989
1990 /* retrieve these captures from the HTTP logs */
1991 { "capture.req.method", smp_fetch_capture_req_method, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
1992 { "capture.req.uri", smp_fetch_capture_req_uri, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
1993 { "capture.req.ver", smp_fetch_capture_req_ver, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
1994
1995 { "capture.res.hdr", smp_fetch_capture_res_hdr, ARG1(1,SINT), NULL, SMP_T_STR, SMP_USE_HRSHP },
1996 { "capture.res.ver", smp_fetch_capture_res_ver, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
1997
1998 /* cookie is valid in both directions (eg: for "stick ...") but cook*
1999 * are only here to match the ACL's name, are request-only and are used
2000 * for ACL compatibility only.
2001 */
2002 { "cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
Christopher Fauletc1f40dd2019-05-16 10:07:30 +02002003 { "cookie", smp_fetch_chn_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV },
Willy Tarreau79e57332018-10-02 16:01:16 +02002004 { "cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2005 { "cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2006
2007 /* hdr is valid in both directions (eg: for "stick ...") but hdr_* are
2008 * only here to match the ACL's name, are request-only and are used for
2009 * ACL compatibility only.
2010 */
Christopher Fauletc1f40dd2019-05-16 10:07:30 +02002011 { "hdr", smp_fetch_chn_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV },
Willy Tarreau79e57332018-10-02 16:01:16 +02002012 { "hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2013 { "hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRQHV },
2014 { "hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRQHV },
2015
Christopher Fauleta4063562019-08-02 11:51:37 +02002016 { "http_auth_type", smp_fetch_http_auth_type, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2017 { "http_auth_user", smp_fetch_http_auth_user, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2018 { "http_auth_pass", smp_fetch_http_auth_pass, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
Willy Tarreau79e57332018-10-02 16:01:16 +02002019 { "http_auth", smp_fetch_http_auth, ARG1(1,USR), NULL, SMP_T_BOOL, SMP_USE_HRQHV },
2020 { "http_auth_group", smp_fetch_http_auth_grp, ARG1(1,USR), NULL, SMP_T_STR, SMP_USE_HRQHV },
2021 { "http_first_req", smp_fetch_http_first_req, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP },
2022 { "method", smp_fetch_meth, 0, NULL, SMP_T_METH, SMP_USE_HRQHP },
2023 { "path", smp_fetch_path, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2024 { "query", smp_fetch_query, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2025
2026 /* HTTP protocol on the request path */
2027 { "req.proto_http", smp_fetch_proto_http, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP },
2028 { "req_proto_http", smp_fetch_proto_http, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP },
2029
2030 /* HTTP version on the request path */
2031 { "req.ver", smp_fetch_rqver, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2032 { "req_ver", smp_fetch_rqver, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2033
2034 { "req.body", smp_fetch_body, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV },
2035 { "req.body_len", smp_fetch_body_len, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV },
2036 { "req.body_size", smp_fetch_body_size, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV },
2037 { "req.body_param", smp_fetch_body_param, ARG1(0,STR), NULL, SMP_T_BIN, SMP_USE_HRQHV },
2038
2039 { "req.hdrs", smp_fetch_hdrs, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV },
2040 { "req.hdrs_bin", smp_fetch_hdrs_bin, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV },
2041
2042 /* HTTP version on the response path */
2043 { "res.ver", smp_fetch_stver, 0, NULL, SMP_T_STR, SMP_USE_HRSHV },
2044 { "resp_ver", smp_fetch_stver, 0, NULL, SMP_T_STR, SMP_USE_HRSHV },
2045
2046 /* explicit req.{cook,hdr} are used to force the fetch direction to be request-only */
2047 { "req.cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
2048 { "req.cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2049 { "req.cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2050
2051 { "req.fhdr", smp_fetch_fhdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV },
2052 { "req.fhdr_cnt", smp_fetch_fhdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2053 { "req.hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV },
2054 { "req.hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2055 { "req.hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRQHV },
2056 { "req.hdr_names", smp_fetch_hdr_names, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
2057 { "req.hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRQHV },
2058
2059 /* explicit req.{cook,hdr} are used to force the fetch direction to be response-only */
2060 { "res.cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV },
2061 { "res.cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2062 { "res.cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2063
2064 { "res.fhdr", smp_fetch_fhdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV },
2065 { "res.fhdr_cnt", smp_fetch_fhdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2066 { "res.hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV },
2067 { "res.hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2068 { "res.hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRSHV },
2069 { "res.hdr_names", smp_fetch_hdr_names, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV },
2070 { "res.hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRSHV },
2071
2072 /* scook is valid only on the response and is used for ACL compatibility */
2073 { "scook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV },
2074 { "scook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2075 { "scook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2076 { "set-cookie", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV }, /* deprecated */
2077
2078 /* shdr is valid only on the response and is used for ACL compatibility */
2079 { "shdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV },
2080 { "shdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2081 { "shdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRSHV },
2082 { "shdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRSHV },
2083
2084 { "status", smp_fetch_stcode, 0, NULL, SMP_T_SINT, SMP_USE_HRSHP },
2085 { "unique-id", smp_fetch_uniqueid, 0, NULL, SMP_T_STR, SMP_SRC_L4SRV },
2086 { "url", smp_fetch_url, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2087 { "url32", smp_fetch_url32, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV },
2088 { "url32+src", smp_fetch_url32_src, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV },
2089 { "url_ip", smp_fetch_url_ip, 0, NULL, SMP_T_IPV4, SMP_USE_HRQHV },
2090 { "url_port", smp_fetch_url_port, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV },
2091 { "url_param", smp_fetch_url_param, ARG2(0,STR,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
2092 { "urlp" , smp_fetch_url_param, ARG2(0,STR,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
2093 { "urlp_val", smp_fetch_url_param_val, ARG2(0,STR,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2094 { /* END */ },
2095}};
2096
Willy Tarreau0108d902018-11-25 19:14:37 +01002097INITCALL1(STG_REGISTER, sample_register_fetches, &sample_fetch_keywords);
Willy Tarreau79e57332018-10-02 16:01:16 +02002098
2099/*
2100 * Local variables:
2101 * c-indent-level: 8
2102 * c-basic-offset: 8
2103 * End:
2104 */