blob: 765c4458f4964ea69a84314912bc6e41cafdad1e [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.
91 */
92
Christopher Fauletcd761952019-07-15 13:58:29 +020093static int get_http_auth(struct sample *smp, struct htx *htx)
Willy Tarreau79e57332018-10-02 16:01:16 +020094{
Christopher Faulet311c7ea2018-10-24 21:41:55 +020095 struct stream *s = smp->strm;
Willy Tarreau79e57332018-10-02 16:01:16 +020096 struct http_txn *txn = s->txn;
Christopher Faulet6d1dd462019-07-15 14:36:03 +020097 struct http_hdr_ctx ctx = { .blk = NULL };
98 struct ist hdr;
Willy Tarreau79e57332018-10-02 16:01:16 +020099 struct buffer auth_method;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200100 char *p;
Willy Tarreau79e57332018-10-02 16:01:16 +0200101 int len;
102
103#ifdef DEBUG_AUTH
104 printf("Auth for stream %p: %d\n", s, txn->auth.method);
105#endif
Willy Tarreau79e57332018-10-02 16:01:16 +0200106 if (txn->auth.method == HTTP_AUTH_WRONG)
107 return 0;
108
109 txn->auth.method = HTTP_AUTH_WRONG;
110
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200111 if (txn->flags & TX_USE_PX_CONN)
112 hdr = ist("Proxy-Authorization");
113 else
114 hdr = ist("Authorization");
Willy Tarreau79e57332018-10-02 16:01:16 +0200115
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200116 ctx.blk = NULL;
117 if (!http_find_header(htx, hdr, &ctx, 0))
118 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200119
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200120 p = memchr(ctx.value.ptr, ' ', ctx.value.len);
121 len = p - ctx.value.ptr;
122 if (!p || len <= 0)
123 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200124
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200125 if (chunk_initlen(&auth_method, ctx.value.ptr, 0, len) != 1)
126 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200127
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200128 chunk_initlen(&txn->auth.method_data, p + 1, 0, ctx.value.len - len - 1);
Willy Tarreau79e57332018-10-02 16:01:16 +0200129
130 if (!strncasecmp("Basic", auth_method.area, auth_method.data)) {
131 struct buffer *http_auth = get_trash_chunk();
132
133 len = base64dec(txn->auth.method_data.area,
134 txn->auth.method_data.data,
135 http_auth->area, global.tune.bufsize - 1);
136
137 if (len < 0)
138 return 0;
139
140
141 http_auth->area[len] = '\0';
142
143 p = strchr(http_auth->area, ':');
144
145 if (!p)
146 return 0;
147
148 txn->auth.user = http_auth->area;
149 *p = '\0';
150 txn->auth.pass = p+1;
151
152 txn->auth.method = HTTP_AUTH_BASIC;
153 return 1;
154 }
155
156 return 0;
157}
158
159/* This function ensures that the prerequisites for an L7 fetch are ready,
160 * which means that a request or response is ready. If some data is missing,
161 * a parsing attempt is made. This is useful in TCP-based ACLs which are able
Christopher Faulet5ec8bcb2019-04-17 12:04:12 +0200162 * to extract data from L7. If <vol> is non-null during a prefetch, another
163 * test is made to ensure the required information is not gone.
Christopher Fauletef453ed2018-10-24 21:39:27 +0200164 *
165 * The function returns :
166 * NULL with SMP_F_MAY_CHANGE in the sample flags if some data is missing to
167 * decide whether or not an HTTP message is present ;
168 * NULL if the requested data cannot be fetched or if it is certain that
169 * we'll never have any HTTP message there ;
170 * The HTX message if ready
171 */
Christopher Faulet5ec8bcb2019-04-17 12:04:12 +0200172struct htx *smp_prefetch_htx(struct sample *smp, struct channel *chn, int vol)
Christopher Fauletef453ed2018-10-24 21:39:27 +0200173{
Christopher Fauletef453ed2018-10-24 21:39:27 +0200174 struct stream *s = smp->strm;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200175 struct http_txn *txn = NULL;
176 struct htx *htx = NULL;
Christopher Faulet89dc4992019-04-17 12:02:59 +0200177 struct http_msg *msg;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100178 struct htx_sl *sl;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200179
180 /* Note: it is possible that <s> is NULL when called before stream
181 * initialization (eg: tcp-request connection), so this function is the
182 * one responsible for guarding against this case for all HTTP users.
183 */
Christopher Faulet89dc4992019-04-17 12:02:59 +0200184 if (!s || !chn)
Christopher Fauletef453ed2018-10-24 21:39:27 +0200185 return NULL;
186
187 if (!s->txn) {
188 if (unlikely(!http_alloc_txn(s)))
189 return NULL; /* not enough memory */
190 http_init_txn(s);
191 txn = s->txn;
192 }
Christopher Faulet89dc4992019-04-17 12:02:59 +0200193 txn = s->txn;
194 msg = (!(chn->flags & CF_ISRESP) ? &txn->req : &txn->rsp);
195 smp->data.type = SMP_T_BOOL;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200196
Christopher Fauleteca88542019-04-03 10:12:42 +0200197 if (IS_HTX_STRM(s)) {
Christopher Faulet89dc4992019-04-17 12:02:59 +0200198 htx = htxbuf(&chn->buf);
Christopher Fauletef453ed2018-10-24 21:39:27 +0200199
Christopher Faulet89dc4992019-04-17 12:02:59 +0200200 if (msg->msg_state == HTTP_MSG_ERROR || (htx->flags & HTX_FL_PARSING_ERROR))
201 return NULL;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200202
Christopher Faulet89dc4992019-04-17 12:02:59 +0200203 if (msg->msg_state < HTTP_MSG_BODY) {
204 /* Analyse not yet started */
Christopher Faulet29f17582019-05-23 11:03:26 +0200205 if (htx_is_empty(htx) || htx->first == -1) {
Christopher Fauletef453ed2018-10-24 21:39:27 +0200206 /* Parsing is done by the mux, just wait */
207 smp->flags |= SMP_F_MAY_CHANGE;
208 return NULL;
209 }
210 }
Christopher Faulet297fbb42019-05-13 14:41:27 +0200211 sl = http_get_stline(htx);
Christopher Faulet5ec8bcb2019-04-17 12:04:12 +0200212 if (vol && !sl) {
Christopher Faulet89dc4992019-04-17 12:02:59 +0200213 /* The start-line was already forwarded, it is too late to fetch anything */
214 return NULL;
215 }
Christopher Fauletef453ed2018-10-24 21:39:27 +0200216 }
Christopher Fauleteca88542019-04-03 10:12:42 +0200217 else { /* RAW mode */
Christopher Faulet89dc4992019-04-17 12:02:59 +0200218 struct buffer *buf;
219 struct h1m h1m;
Christopher Faulete4ab11b2019-06-11 15:05:37 +0200220 struct http_hdr hdrs[global.tune.max_http_hdr];
Christopher Faulet89dc4992019-04-17 12:02:59 +0200221 union h1_sl h1sl;
222 unsigned int flags = HTX_FL_NONE;
223 int ret;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200224
Christopher Faulet89dc4992019-04-17 12:02:59 +0200225 /* no HTTP fetch on the response in TCP mode */
226 if (chn->flags & CF_ISRESP)
227 return NULL;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200228
Christopher Faulet89dc4992019-04-17 12:02:59 +0200229 /* Now we are working on the request only */
230 buf = &chn->buf;
231 if (b_head(buf) + b_data(buf) > b_wrap(buf))
232 b_slow_realign(buf, trash.area, 0);
Christopher Fauletef453ed2018-10-24 21:39:27 +0200233
Christopher Faulet89dc4992019-04-17 12:02:59 +0200234 h1m_init_req(&h1m);
235 ret = h1_headers_to_hdr_list(b_head(buf), b_stop(buf),
236 hdrs, sizeof(hdrs)/sizeof(hdrs[0]), &h1m, &h1sl);
237 if (ret <= 0) {
238 /* Invalid or too big*/
239 if (ret < 0 || channel_full(&s->req, global.tune.maxrewrite))
Christopher Fauletef453ed2018-10-24 21:39:27 +0200240 return NULL;
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100241
Christopher Faulet89dc4992019-04-17 12:02:59 +0200242 /* wait for a full request */
243 smp->flags |= SMP_F_MAY_CHANGE;
244 return NULL;
245 }
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100246
Christopher Faulet89dc4992019-04-17 12:02:59 +0200247 /* OK we just got a valid HTTP mesage. We have to convert it
248 * into an HTX message.
249 */
250 if (unlikely(h1sl.rq.v.len == 0)) {
251 /* try to convert HTTP/0.9 requests to HTTP/1.0 */
252 if (h1sl.rq.meth != HTTP_METH_GET || !h1sl.rq.u.len)
Christopher Fauletef453ed2018-10-24 21:39:27 +0200253 return NULL;
Christopher Faulet89dc4992019-04-17 12:02:59 +0200254 h1sl.rq.v = ist("HTTP/1.0");
Christopher Fauletef453ed2018-10-24 21:39:27 +0200255 }
Christopher Faulet89dc4992019-04-17 12:02:59 +0200256
257 /* Set HTX start-line flags */
258 if (h1m.flags & H1_MF_VER_11)
259 flags |= HTX_SL_F_VER_11;
260 if (h1m.flags & H1_MF_XFER_ENC)
261 flags |= HTX_SL_F_XFER_ENC;
262 flags |= HTX_SL_F_XFER_LEN;
263 if (h1m.flags & H1_MF_CHNK)
264 flags |= HTX_SL_F_CHNK;
265 else if (h1m.flags & H1_MF_CLEN)
266 flags |= HTX_SL_F_CLEN;
267
Richard Russo458eafb2019-07-31 11:45:56 -0700268 htx = htx_from_buf(get_raw_htx_chunk());
Christopher Faulet89dc4992019-04-17 12:02:59 +0200269 sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, h1sl.rq.m, h1sl.rq.u, h1sl.rq.v);
270 if (!sl || !htx_add_all_headers(htx, hdrs))
Christopher Fauletef453ed2018-10-24 21:39:27 +0200271 return NULL;
Willy Tarreauce9bbf52019-05-13 08:32:31 +0200272 sl->info.req.meth = h1sl.rq.meth;
Christopher Faulet89dc4992019-04-17 12:02:59 +0200273 }
274
275 /* OK we just got a valid HTTP message. If not already done by
276 * HTTP analyzers, we have some minor preparation to perform so
277 * that further checks can rely on HTTP tests.
278 */
279 if (sl && msg->msg_state < HTTP_MSG_BODY) {
280 if (!(chn->flags & CF_ISRESP)) {
281 txn->meth = sl->info.req.meth;
282 if (txn->meth == HTTP_METH_GET || txn->meth == HTTP_METH_HEAD)
283 s->flags |= SF_REDIRECTABLE;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200284 }
Christopher Faulet89dc4992019-04-17 12:02:59 +0200285 else
286 txn->status = sl->info.res.status;
287 if (sl->flags & HTX_SL_F_VER_11)
288 msg->flags |= HTTP_MSGF_VER_11;
Christopher Fauletef453ed2018-10-24 21:39:27 +0200289 }
290
291 /* everything's OK */
292 smp->data.u.sint = 1;
293 return htx;
294}
295
Willy Tarreau79e57332018-10-02 16:01:16 +0200296/* This function fetches the method of current HTTP request and stores
297 * it in the global pattern struct as a chunk. There are two possibilities :
298 * - if the method is known (not HTTP_METH_OTHER), its identifier is stored
299 * in <len> and <ptr> is NULL ;
300 * - if the method is unknown (HTTP_METH_OTHER), <ptr> points to the text and
301 * <len> to its length.
302 * This is intended to be used with pat_match_meth() only.
303 */
304static int smp_fetch_meth(const struct arg *args, struct sample *smp, const char *kw, void *private)
305{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200306 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200307 struct htx *htx = smp_prefetch_htx(smp, chn, 0);
Willy Tarreau79e57332018-10-02 16:01:16 +0200308 struct http_txn *txn;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200309 int meth;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200310
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200311 if (!htx)
312 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200313
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200314 txn = smp->strm->txn;
315 meth = txn->meth;
316 smp->data.type = SMP_T_METH;
317 smp->data.u.meth.meth = meth;
318 if (meth == HTTP_METH_OTHER) {
319 struct htx_sl *sl;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200320
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200321 if ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) {
322 /* ensure the indexes are not affected */
323 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200324 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200325 sl = http_get_stline(htx);
326 smp->flags |= SMP_F_CONST;
327 smp->data.u.meth.str.area = HTX_SL_REQ_MPTR(sl);
328 smp->data.u.meth.str.data = HTX_SL_REQ_MLEN(sl);
Willy Tarreau79e57332018-10-02 16:01:16 +0200329 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200330 smp->flags |= SMP_F_VOL_1ST;
Willy Tarreau79e57332018-10-02 16:01:16 +0200331 return 1;
332}
333
334static int smp_fetch_rqver(const struct arg *args, struct sample *smp, const char *kw, void *private)
335{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200336 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200337 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
338 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +0200339 char *ptr;
340 int len;
341
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200342 if (!htx)
343 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200344
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200345 sl = http_get_stline(htx);
346 len = HTX_SL_REQ_VLEN(sl);
347 ptr = HTX_SL_REQ_VPTR(sl);
Willy Tarreau79e57332018-10-02 16:01:16 +0200348
349 while ((len-- > 0) && (*ptr++ != '/'));
350 if (len <= 0)
351 return 0;
352
353 smp->data.type = SMP_T_STR;
354 smp->data.u.str.area = ptr;
355 smp->data.u.str.data = len;
356
357 smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
358 return 1;
359}
360
361static int smp_fetch_stver(const struct arg *args, struct sample *smp, const char *kw, void *private)
362{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200363 struct channel *chn = SMP_RES_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200364 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
365 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +0200366 char *ptr;
367 int len;
368
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200369 if (!htx)
370 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200371
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200372 sl = http_get_stline(htx);
373 len = HTX_SL_RES_VLEN(sl);
374 ptr = HTX_SL_RES_VPTR(sl);
Willy Tarreau79e57332018-10-02 16:01:16 +0200375
376 while ((len-- > 0) && (*ptr++ != '/'));
377 if (len <= 0)
378 return 0;
379
380 smp->data.type = SMP_T_STR;
381 smp->data.u.str.area = ptr;
382 smp->data.u.str.data = len;
383
384 smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
385 return 1;
386}
387
388/* 3. Check on Status Code. We manipulate integers here. */
389static int smp_fetch_stcode(const struct arg *args, struct sample *smp, const char *kw, void *private)
390{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200391 struct channel *chn = SMP_RES_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200392 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
393 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +0200394 char *ptr;
395 int len;
396
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200397 if (!htx)
398 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200399
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200400 sl = http_get_stline(htx);
401 len = HTX_SL_RES_CLEN(sl);
402 ptr = HTX_SL_RES_CPTR(sl);
Willy Tarreau79e57332018-10-02 16:01:16 +0200403
404 smp->data.type = SMP_T_SINT;
405 smp->data.u.sint = __strl2ui(ptr, len);
406 smp->flags = SMP_F_VOL_1ST;
407 return 1;
408}
409
410static int smp_fetch_uniqueid(const struct arg *args, struct sample *smp, const char *kw, void *private)
411{
Tim Duesterhusa17e6622020-03-05 20:19:02 +0100412 struct ist unique_id;
Tim Duesterhus2825b4b2020-02-28 15:13:34 +0100413
Willy Tarreau79e57332018-10-02 16:01:16 +0200414 if (LIST_ISEMPTY(&smp->sess->fe->format_unique_id))
415 return 0;
416
Willy Tarreaua1062a42020-04-29 11:50:38 +0200417 if (!smp->strm)
418 return 0;
419
Tim Duesterhusa17e6622020-03-05 20:19:02 +0100420 unique_id = stream_generate_unique_id(smp->strm, &smp->sess->fe->format_unique_id);
421 if (!isttest(unique_id))
Tim Duesterhus2825b4b2020-02-28 15:13:34 +0100422 return 0;
423
Tim Duesterhusa17e6622020-03-05 20:19:02 +0100424 smp->data.u.str.area = smp->strm->unique_id.ptr;
425 smp->data.u.str.data = smp->strm->unique_id.len;
Tim Duesterhus2825b4b2020-02-28 15:13:34 +0100426 smp->data.type = SMP_T_STR;
Willy Tarreau79e57332018-10-02 16:01:16 +0200427 smp->flags = SMP_F_CONST;
428 return 1;
429}
430
431/* Returns a string block containing all headers including the
Joseph Herlant942eea32018-11-15 13:57:22 -0800432 * empty line which separes headers from the body. This is useful
433 * for some headers analysis.
Willy Tarreau79e57332018-10-02 16:01:16 +0200434 */
435static int smp_fetch_hdrs(const struct arg *args, struct sample *smp, const char *kw, void *private)
436{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200437 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200438 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
439 struct buffer *temp;
440 int32_t pos;
Willy Tarreau79e57332018-10-02 16:01:16 +0200441
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200442 if (!htx)
443 return 0;
444 temp = get_trash_chunk();
445 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
446 struct htx_blk *blk = htx_get_blk(htx, pos);
447 enum htx_blk_type type = htx_get_blk_type(blk);
Willy Tarreau79e57332018-10-02 16:01:16 +0200448
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200449 if (type == HTX_BLK_HDR) {
450 struct ist n = htx_get_blk_name(htx, blk);
451 struct ist v = htx_get_blk_value(htx, blk);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200452
Christopher Faulet53a899b2019-10-08 16:38:42 +0200453 if (!h1_format_htx_hdr(n, v, temp))
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200454 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200455 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200456 else if (type == HTX_BLK_EOH) {
457 if (!chunk_memcat(temp, "\r\n", 2))
458 return 0;
459 break;
460 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200461 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200462 smp->data.type = SMP_T_STR;
463 smp->data.u.str = *temp;
Willy Tarreau79e57332018-10-02 16:01:16 +0200464 return 1;
465}
466
467/* Returns the header request in a length/value encoded format.
468 * This is useful for exchanges with the SPOE.
469 *
470 * A "length value" is a multibyte code encoding numbers. It uses the
471 * SPOE format. The encoding is the following:
472 *
473 * Each couple "header name" / "header value" is composed
474 * like this:
475 * "length value" "header name bytes"
476 * "length value" "header value bytes"
477 * When the last header is reached, the header name and the header
478 * value are empty. Their length are 0
479 */
480static int smp_fetch_hdrs_bin(const struct arg *args, struct sample *smp, const char *kw, void *private)
481{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200482 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200483 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200484 struct buffer *temp;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200485 char *p, *end;
486 int32_t pos;
487 int ret;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200488
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200489 if (!htx)
490 return 0;
491 temp = get_trash_chunk();
492 p = temp->area;
493 end = temp->area + temp->size;
494 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
495 struct htx_blk *blk = htx_get_blk(htx, pos);
496 enum htx_blk_type type = htx_get_blk_type(blk);
497 struct ist n, v;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200498
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200499 if (type == HTX_BLK_HDR) {
500 n = htx_get_blk_name(htx,blk);
501 v = htx_get_blk_value(htx, blk);
Willy Tarreau79e57332018-10-02 16:01:16 +0200502
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200503 /* encode the header name. */
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200504 ret = encode_varint(n.len, &p, end);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200505 if (ret == -1)
506 return 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200507 if (p + n.len > end)
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200508 return 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200509 memcpy(p, n.ptr, n.len);
510 p += n.len;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200511
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200512 /* encode the header value. */
513 ret = encode_varint(v.len, &p, end);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200514 if (ret == -1)
515 return 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200516 if (p + v.len > end)
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200517 return 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200518 memcpy(p, v.ptr, v.len);
519 p += v.len;
Willy Tarreau79e57332018-10-02 16:01:16 +0200520
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200521 }
522 else if (type == HTX_BLK_EOH) {
523 /* encode the end of the header list with empty
524 * header name and header value.
525 */
526 ret = encode_varint(0, &p, end);
527 if (ret == -1)
528 return 0;
529 ret = encode_varint(0, &p, end);
530 if (ret == -1)
531 return 0;
532 break;
533 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200534 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200535
536 /* Initialise sample data which will be filled. */
537 smp->data.type = SMP_T_BIN;
538 smp->data.u.str.area = temp->area;
539 smp->data.u.str.data = p - temp->area;
540 smp->data.u.str.size = temp->size;
Willy Tarreau79e57332018-10-02 16:01:16 +0200541 return 1;
542}
543
544/* returns the longest available part of the body. This requires that the body
545 * has been waited for using http-buffer-request.
546 */
547static int smp_fetch_body(const struct arg *args, struct sample *smp, const char *kw, void *private)
548{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200549 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200550 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
Willy Tarreau79e57332018-10-02 16:01:16 +0200551 struct buffer *temp;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200552 int32_t pos;
Willy Tarreau79e57332018-10-02 16:01:16 +0200553
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200554 if (!htx)
555 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200556
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200557 temp = get_trash_chunk();
558 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
559 struct htx_blk *blk = htx_get_blk(htx, pos);
560 enum htx_blk_type type = htx_get_blk_type(blk);
Willy Tarreau79e57332018-10-02 16:01:16 +0200561
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200562 if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
563 break;
564 if (type == HTX_BLK_DATA) {
Christopher Faulet53a899b2019-10-08 16:38:42 +0200565 if (!h1_format_htx_data(htx_get_blk_value(htx, blk), temp, 0))
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200566 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200567 }
Willy Tarreau79e57332018-10-02 16:01:16 +0200568 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200569
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200570 smp->data.type = SMP_T_BIN;
571 smp->data.u.str = *temp;
572 smp->flags = SMP_F_VOL_TEST;
Willy Tarreau79e57332018-10-02 16:01:16 +0200573 return 1;
574}
575
576
577/* returns the available length of the body. This requires that the body
578 * has been waited for using http-buffer-request.
579 */
580static int smp_fetch_body_len(const struct arg *args, struct sample *smp, const char *kw, void *private)
581{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200582 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200583 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
584 int32_t pos;
585 unsigned long long len = 0;
Christopher Fauletc16317d2018-12-12 14:11:22 +0100586
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200587 if (!htx)
588 return 0;
Christopher Fauletc16317d2018-12-12 14:11:22 +0100589
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200590 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
591 struct htx_blk *blk = htx_get_blk(htx, pos);
592 enum htx_blk_type type = htx_get_blk_type(blk);
Christopher Fauletc16317d2018-12-12 14:11:22 +0100593
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200594 if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
595 break;
596 if (type == HTX_BLK_DATA)
597 len += htx_get_blksz(blk);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200598 }
Willy Tarreau79e57332018-10-02 16:01:16 +0200599
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200600 smp->data.type = SMP_T_SINT;
601 smp->data.u.sint = len;
602 smp->flags = SMP_F_VOL_TEST;
Willy Tarreau79e57332018-10-02 16:01:16 +0200603 return 1;
604}
605
606
607/* returns the advertised length of the body, or the advertised size of the
608 * chunks available in the buffer. This requires that the body has been waited
609 * for using http-buffer-request.
610 */
611static int smp_fetch_body_size(const struct arg *args, struct sample *smp, const char *kw, void *private)
612{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200613 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200614 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
615 int32_t pos;
616 unsigned long long len = 0;
Christopher Faulet89dc4992019-04-17 12:02:59 +0200617
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200618 if (!htx)
619 return 0;
Christopher Fauletc16317d2018-12-12 14:11:22 +0100620
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200621 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
622 struct htx_blk *blk = htx_get_blk(htx, pos);
623 enum htx_blk_type type = htx_get_blk_type(blk);
Christopher Fauletc16317d2018-12-12 14:11:22 +0100624
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200625 if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
626 break;
627 if (type == HTX_BLK_DATA)
628 len += htx_get_blksz(blk);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200629 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200630 if (htx->extra != ULLONG_MAX)
631 len += htx->extra;
Willy Tarreau79e57332018-10-02 16:01:16 +0200632
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200633 smp->data.type = SMP_T_SINT;
634 smp->data.u.sint = len;
635 smp->flags = SMP_F_VOL_TEST;
Willy Tarreau79e57332018-10-02 16:01:16 +0200636 return 1;
637}
638
639
640/* 4. Check on URL/URI. A pointer to the URI is stored. */
641static int smp_fetch_url(const struct arg *args, struct sample *smp, const char *kw, void *private)
642{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200643 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200644 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
645 struct htx_sl *sl;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200646
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200647 if (!htx)
648 return 0;
649 sl = http_get_stline(htx);
650 smp->data.type = SMP_T_STR;
651 smp->data.u.str.area = HTX_SL_REQ_UPTR(sl);
652 smp->data.u.str.data = HTX_SL_REQ_ULEN(sl);
653 smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
Willy Tarreau79e57332018-10-02 16:01:16 +0200654 return 1;
655}
656
657static int smp_fetch_url_ip(const struct arg *args, struct sample *smp, const char *kw, void *private)
658{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200659 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200660 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
661 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +0200662 struct sockaddr_storage addr;
663
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200664 if (!htx)
665 return 0;
666 sl = http_get_stline(htx);
667 url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL);
Willy Tarreau79e57332018-10-02 16:01:16 +0200668
Willy Tarreau79e57332018-10-02 16:01:16 +0200669 if (((struct sockaddr_in *)&addr)->sin_family != AF_INET)
670 return 0;
671
672 smp->data.type = SMP_T_IPV4;
673 smp->data.u.ipv4 = ((struct sockaddr_in *)&addr)->sin_addr;
674 smp->flags = 0;
675 return 1;
676}
677
678static int smp_fetch_url_port(const struct arg *args, struct sample *smp, const char *kw, void *private)
679{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200680 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200681 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
682 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +0200683 struct sockaddr_storage addr;
684
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200685 if (!htx)
686 return 0;
687 sl = http_get_stline(htx);
688 url2sa(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), &addr, NULL);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200689
Willy Tarreau79e57332018-10-02 16:01:16 +0200690 if (((struct sockaddr_in *)&addr)->sin_family != AF_INET)
691 return 0;
692
693 smp->data.type = SMP_T_SINT;
694 smp->data.u.sint = ntohs(((struct sockaddr_in *)&addr)->sin_port);
695 smp->flags = 0;
696 return 1;
697}
698
699/* Fetch an HTTP header. A pointer to the beginning of the value is returned.
700 * Accepts an optional argument of type string containing the header field name,
701 * and an optional argument of type signed or unsigned integer to request an
702 * explicit occurrence of the header. Note that in the event of a missing name,
703 * headers are considered from the first one. It does not stop on commas and
704 * returns full lines instead (useful for User-Agent or Date for example).
705 */
706static int smp_fetch_fhdr(const struct arg *args, struct sample *smp, const char *kw, void *private)
707{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200708 /* possible keywords: req.fhdr, res.fhdr */
709 struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200710 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
711 struct http_hdr_ctx *ctx = smp->ctx.a[0];
712 struct ist name;
Willy Tarreau79e57332018-10-02 16:01:16 +0200713 int occ = 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200714
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200715 if (!ctx) {
716 /* first call */
717 ctx = &static_http_hdr_ctx;
718 ctx->blk = NULL;
719 smp->ctx.a[0] = ctx;
720 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200721
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200722 if (args) {
723 if (args[0].type != ARGT_STR)
Willy Tarreau79e57332018-10-02 16:01:16 +0200724 return 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200725 name.ptr = args[0].data.str.area;
726 name.len = args[0].data.str.data;
Willy Tarreau79e57332018-10-02 16:01:16 +0200727
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200728 if (args[1].type == ARGT_SINT)
729 occ = args[1].data.sint;
Willy Tarreau79e57332018-10-02 16:01:16 +0200730 }
731
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200732 if (!htx)
733 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200734
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200735 if (ctx && !(smp->flags & SMP_F_NOT_LAST))
736 /* search for header from the beginning */
737 ctx->blk = NULL;
Willy Tarreau79e57332018-10-02 16:01:16 +0200738
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200739 if (!occ && !(smp->opt & SMP_OPT_ITERATE))
740 /* no explicit occurrence and single fetch => last header by default */
741 occ = -1;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200742
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200743 if (!occ)
744 /* prepare to report multiple occurrences for ACL fetches */
745 smp->flags |= SMP_F_NOT_LAST;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200746
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200747 smp->data.type = SMP_T_STR;
748 smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST;
749 if (http_get_htx_fhdr(htx, name, occ, ctx, &smp->data.u.str.area, &smp->data.u.str.data))
750 return 1;
Willy Tarreau79e57332018-10-02 16:01:16 +0200751 smp->flags &= ~SMP_F_NOT_LAST;
752 return 0;
753}
754
755/* 6. Check on HTTP header count. The number of occurrences is returned.
756 * Accepts exactly 1 argument of type string. It does not stop on commas and
757 * returns full lines instead (useful for User-Agent or Date for example).
758 */
759static int smp_fetch_fhdr_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
760{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200761 /* possible keywords: req.fhdr_cnt, res.fhdr_cnt */
762 struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200763 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
764 struct http_hdr_ctx ctx;
765 struct ist name;
Willy Tarreau79e57332018-10-02 16:01:16 +0200766 int cnt;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200767
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200768 if (!htx)
769 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200770
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200771 if (args && args->type == ARGT_STR) {
772 name.ptr = args->data.str.area;
773 name.len = args->data.str.data;
774 } else {
775 name.ptr = NULL;
776 name.len = 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200777 }
Willy Tarreau79e57332018-10-02 16:01:16 +0200778
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200779 ctx.blk = NULL;
780 cnt = 0;
781 while (http_find_header(htx, name, &ctx, 1))
782 cnt++;
Willy Tarreau79e57332018-10-02 16:01:16 +0200783 smp->data.type = SMP_T_SINT;
784 smp->data.u.sint = cnt;
785 smp->flags = SMP_F_VOL_HDR;
786 return 1;
787}
788
789static int smp_fetch_hdr_names(const struct arg *args, struct sample *smp, const char *kw, void *private)
790{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200791 /* possible keywords: req.hdr_names, res.hdr_names */
792 struct channel *chn = ((kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200793 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
Willy Tarreau79e57332018-10-02 16:01:16 +0200794 struct buffer *temp;
795 char del = ',';
796
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200797 int32_t pos;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200798
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200799 if (!htx)
800 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200801
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200802 if (args && args->type == ARGT_STR)
803 del = *args[0].data.str.area;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200804
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200805 temp = get_trash_chunk();
806 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
807 struct htx_blk *blk = htx_get_blk(htx, pos);
808 enum htx_blk_type type = htx_get_blk_type(blk);
809 struct ist n;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200810
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200811 if (type == HTX_BLK_EOH)
812 break;
813 if (type != HTX_BLK_HDR)
814 continue;
815 n = htx_get_blk_name(htx, blk);
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200816
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200817 if (temp->data)
818 temp->area[temp->data++] = del;
819 chunk_memcat(temp, n.ptr, n.len);
Willy Tarreau79e57332018-10-02 16:01:16 +0200820 }
821
822 smp->data.type = SMP_T_STR;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200823 smp->data.u.str = *temp;
Willy Tarreau79e57332018-10-02 16:01:16 +0200824 smp->flags = SMP_F_VOL_HDR;
825 return 1;
826}
827
828/* Fetch an HTTP header. A pointer to the beginning of the value is returned.
829 * Accepts an optional argument of type string containing the header field name,
830 * and an optional argument of type signed or unsigned integer to request an
831 * explicit occurrence of the header. Note that in the event of a missing name,
832 * headers are considered from the first one.
833 */
834static int smp_fetch_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private)
835{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200836 /* possible keywords: req.hdr / hdr, res.hdr / shdr */
837 struct channel *chn = ((kw[0] == 'h' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200838 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
839 struct http_hdr_ctx *ctx = smp->ctx.a[0];
840 struct ist name;
Willy Tarreau79e57332018-10-02 16:01:16 +0200841 int occ = 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200842
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200843 if (!ctx) {
844 /* first call */
845 ctx = &static_http_hdr_ctx;
846 ctx->blk = NULL;
847 smp->ctx.a[0] = ctx;
848 }
Willy Tarreau79e57332018-10-02 16:01:16 +0200849
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200850 if (args) {
851 if (args[0].type != ARGT_STR)
Willy Tarreau79e57332018-10-02 16:01:16 +0200852 return 0;
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200853 name.ptr = args[0].data.str.area;
854 name.len = args[0].data.str.data;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200855
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200856 if (args[1].type == ARGT_SINT)
857 occ = args[1].data.sint;
Willy Tarreau79e57332018-10-02 16:01:16 +0200858 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200859
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200860 if (!htx)
861 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200862
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200863 if (ctx && !(smp->flags & SMP_F_NOT_LAST))
864 /* search for header from the beginning */
865 ctx->blk = NULL;
Willy Tarreau79e57332018-10-02 16:01:16 +0200866
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200867 if (!occ && !(smp->opt & SMP_OPT_ITERATE))
868 /* no explicit occurrence and single fetch => last header by default */
869 occ = -1;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200870
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200871 if (!occ)
872 /* prepare to report multiple occurrences for ACL fetches */
873 smp->flags |= SMP_F_NOT_LAST;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200874
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200875 smp->data.type = SMP_T_STR;
876 smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST;
877 if (http_get_htx_hdr(htx, name, occ, ctx, &smp->data.u.str.area, &smp->data.u.str.data))
878 return 1;
Willy Tarreau79e57332018-10-02 16:01:16 +0200879
880 smp->flags &= ~SMP_F_NOT_LAST;
881 return 0;
882}
883
Christopher Fauletc1f40dd2019-05-16 10:07:30 +0200884/* Same than smp_fetch_hdr() but only relies on the sample direction to choose
885 * the right channel. So instead of duplicating the code, we just change the
886 * keyword and then fallback on smp_fetch_hdr().
887 */
888static int smp_fetch_chn_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private)
889{
890 kw = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ ? "req.hdr" : "res.hdr");
891 return smp_fetch_hdr(args, smp, kw, private);
892}
893
Willy Tarreau79e57332018-10-02 16:01:16 +0200894/* 6. Check on HTTP header count. The number of occurrences is returned.
895 * Accepts exactly 1 argument of type string.
896 */
897static int smp_fetch_hdr_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
898{
Christopher Faulet89dc4992019-04-17 12:02:59 +0200899 /* possible keywords: req.hdr_cnt / hdr_cnt, res.hdr_cnt / shdr_cnt */
900 struct channel *chn = ((kw[0] == 'h' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200901 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
902 struct http_hdr_ctx ctx;
903 struct ist name;
Willy Tarreau79e57332018-10-02 16:01:16 +0200904 int cnt;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200905
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200906 if (!htx)
907 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200908
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200909 if (args && args->type == ARGT_STR) {
910 name.ptr = args->data.str.area;
911 name.len = args->data.str.data;
912 } else {
913 name.ptr = NULL;
914 name.len = 0;
Willy Tarreau79e57332018-10-02 16:01:16 +0200915 }
Willy Tarreau79e57332018-10-02 16:01:16 +0200916
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200917 ctx.blk = NULL;
918 cnt = 0;
919 while (http_find_header(htx, name, &ctx, 0))
920 cnt++;
Willy Tarreau79e57332018-10-02 16:01:16 +0200921
922 smp->data.type = SMP_T_SINT;
923 smp->data.u.sint = cnt;
924 smp->flags = SMP_F_VOL_HDR;
925 return 1;
926}
927
928/* Fetch an HTTP header's integer value. The integer value is returned. It
929 * takes a mandatory argument of type string and an optional one of type int
930 * to designate a specific occurrence. It returns an unsigned integer, which
931 * may or may not be appropriate for everything.
932 */
933static int smp_fetch_hdr_val(const struct arg *args, struct sample *smp, const char *kw, void *private)
934{
935 int ret = smp_fetch_hdr(args, smp, kw, private);
936
937 if (ret > 0) {
938 smp->data.type = SMP_T_SINT;
939 smp->data.u.sint = strl2ic(smp->data.u.str.area,
940 smp->data.u.str.data);
941 }
942
943 return ret;
944}
945
946/* Fetch an HTTP header's IP value. takes a mandatory argument of type string
947 * and an optional one of type int to designate a specific occurrence.
948 * It returns an IPv4 or IPv6 address.
949 */
950static int smp_fetch_hdr_ip(const struct arg *args, struct sample *smp, const char *kw, void *private)
951{
952 int ret;
953
954 while ((ret = smp_fetch_hdr(args, smp, kw, private)) > 0) {
955 if (url2ipv4((char *) smp->data.u.str.area, &smp->data.u.ipv4)) {
956 smp->data.type = SMP_T_IPV4;
957 break;
958 } else {
959 struct buffer *temp = get_trash_chunk();
960 if (smp->data.u.str.data < temp->size - 1) {
961 memcpy(temp->area, smp->data.u.str.area,
962 smp->data.u.str.data);
963 temp->area[smp->data.u.str.data] = '\0';
964 if (inet_pton(AF_INET6, temp->area, &smp->data.u.ipv6)) {
965 smp->data.type = SMP_T_IPV6;
966 break;
967 }
968 }
969 }
970
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200971 /* if the header doesn't match an IP address, fetch next one */
972 if (!(smp->flags & SMP_F_NOT_LAST))
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200973 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200974 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200975 return ret;
976}
Willy Tarreau79e57332018-10-02 16:01:16 +0200977
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200978/* 8. Check on URI PATH. A pointer to the PATH is stored. The path starts at
979 * the first '/' after the possible hostname, and ends before the possible '?'.
980 */
981static int smp_fetch_path(const struct arg *args, struct sample *smp, const char *kw, void *private)
982{
983 struct channel *chn = SMP_REQ_CHN(smp);
984 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
985 struct htx_sl *sl;
986 struct ist path;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200987
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200988 if (!htx)
989 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200990
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200991 sl = http_get_stline(htx);
Jerome Magnin4fb196c2020-02-21 10:49:12 +0100992 path = iststop(http_get_path(htx_sl_req_uri(sl)), '?');
Tim Duesterhused526372020-03-05 17:56:33 +0100993 if (!isttest(path))
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200994 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +0200995
Christopher Faulet6d1dd462019-07-15 14:36:03 +0200996 /* OK, we got the '/' ! */
997 smp->data.type = SMP_T_STR;
998 smp->data.u.str.area = path.ptr;
Jerome Magnin4fb196c2020-02-21 10:49:12 +0100999 smp->data.u.str.data = path.len;
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001000 smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
Willy Tarreau79e57332018-10-02 16:01:16 +02001001 return 1;
1002}
1003
1004/* This produces a concatenation of the first occurrence of the Host header
1005 * followed by the path component if it begins with a slash ('/'). This means
1006 * that '*' will not be added, resulting in exactly the first Host entry.
1007 * If no Host header is found, then the path is returned as-is. The returned
1008 * value is stored in the trash so it does not need to be marked constant.
1009 * The returned sample is of type string.
1010 */
1011static int smp_fetch_base(const struct arg *args, struct sample *smp, const char *kw, void *private)
1012{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001013 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001014 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1015 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +02001016 struct buffer *temp;
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001017 struct http_hdr_ctx ctx;
1018 struct ist path;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001019
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001020 if (!htx)
1021 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001022
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001023 ctx.blk = NULL;
1024 if (!http_find_header(htx, ist("Host"), &ctx, 0) || !ctx.value.len)
1025 return smp_fetch_path(args, smp, kw, private);
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001026
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001027 /* OK we have the header value in ctx.value */
1028 temp = get_trash_chunk();
1029 chunk_memcat(temp, ctx.value.ptr, ctx.value.len);
Willy Tarreau79e57332018-10-02 16:01:16 +02001030
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001031 /* now retrieve the path */
1032 sl = http_get_stline(htx);
1033 path = http_get_path(htx_sl_req_uri(sl));
Tim Duesterhused526372020-03-05 17:56:33 +01001034 if (isttest(path)) {
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001035 size_t len;
Willy Tarreau79e57332018-10-02 16:01:16 +02001036
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001037 for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++)
1038 ;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001039
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001040 if (len && *(path.ptr) == '/')
1041 chunk_memcat(temp, path.ptr, len);
Willy Tarreau79e57332018-10-02 16:01:16 +02001042 }
1043
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001044 smp->data.type = SMP_T_STR;
1045 smp->data.u.str = *temp;
Willy Tarreau79e57332018-10-02 16:01:16 +02001046 smp->flags = SMP_F_VOL_1ST;
1047 return 1;
1048}
1049
1050/* This produces a 32-bit hash of the concatenation of the first occurrence of
1051 * the Host header followed by the path component if it begins with a slash ('/').
1052 * This means that '*' will not be added, resulting in exactly the first Host
1053 * entry. If no Host header is found, then the path is used. The resulting value
1054 * is hashed using the path hash followed by a full avalanche hash and provides a
1055 * 32-bit integer value. This fetch is useful for tracking per-path activity on
1056 * high-traffic sites without having to store whole paths.
1057 */
1058static int smp_fetch_base32(const struct arg *args, struct sample *smp, const char *kw, void *private)
1059{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001060 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001061 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1062 struct htx_sl *sl;
1063 struct http_hdr_ctx ctx;
1064 struct ist path;
Willy Tarreau79e57332018-10-02 16:01:16 +02001065 unsigned int hash = 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001066
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001067 if (!htx)
1068 return 0;
Dragan Dosen8861e1c2019-02-12 19:50:31 +01001069
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001070 ctx.blk = NULL;
1071 if (http_find_header(htx, ist("Host"), &ctx, 0)) {
1072 /* OK we have the header value in ctx.value */
1073 while (ctx.value.len--)
1074 hash = *(ctx.value.ptr++) + (hash << 6) + (hash << 16) - hash;
Willy Tarreau79e57332018-10-02 16:01:16 +02001075 }
1076
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001077 /* now retrieve the path */
1078 sl = http_get_stline(htx);
1079 path = http_get_path(htx_sl_req_uri(sl));
Tim Duesterhused526372020-03-05 17:56:33 +01001080 if (isttest(path)) {
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001081 size_t len;
Willy Tarreau79e57332018-10-02 16:01:16 +02001082
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001083 for (len = 0; len < path.len && *(path.ptr + len) != '?'; len++)
1084 ;
Willy Tarreau79e57332018-10-02 16:01:16 +02001085
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001086 if (len && *(path.ptr) == '/') {
1087 while (len--)
1088 hash = *(path.ptr++) + (hash << 6) + (hash << 16) - hash;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001089 }
Willy Tarreau79e57332018-10-02 16:01:16 +02001090 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001091
Willy Tarreau79e57332018-10-02 16:01:16 +02001092 hash = full_hash(hash);
1093
1094 smp->data.type = SMP_T_SINT;
1095 smp->data.u.sint = hash;
1096 smp->flags = SMP_F_VOL_1ST;
1097 return 1;
1098}
1099
1100/* This concatenates the source address with the 32-bit hash of the Host and
1101 * path as returned by smp_fetch_base32(). The idea is to have per-source and
1102 * per-path counters. The result is a binary block from 8 to 20 bytes depending
1103 * on the source address length. The path hash is stored before the address so
1104 * that in environments where IPv6 is insignificant, truncating the output to
1105 * 8 bytes would still work.
1106 */
1107static int smp_fetch_base32_src(const struct arg *args, struct sample *smp, const char *kw, void *private)
1108{
1109 struct buffer *temp;
1110 struct connection *cli_conn = objt_conn(smp->sess->origin);
1111
Willy Tarreaucd7ca792019-07-17 16:57:03 +02001112 if (!cli_conn || !conn_get_src(cli_conn))
Willy Tarreau79e57332018-10-02 16:01:16 +02001113 return 0;
1114
1115 if (!smp_fetch_base32(args, smp, kw, private))
1116 return 0;
1117
1118 temp = get_trash_chunk();
1119 *(unsigned int *) temp->area = htonl(smp->data.u.sint);
1120 temp->data += sizeof(unsigned int);
1121
Willy Tarreau9a1efe12019-07-17 17:13:50 +02001122 switch (cli_conn->src->ss_family) {
Willy Tarreau79e57332018-10-02 16:01:16 +02001123 case AF_INET:
1124 memcpy(temp->area + temp->data,
Willy Tarreau9a1efe12019-07-17 17:13:50 +02001125 &((struct sockaddr_in *)cli_conn->src)->sin_addr,
Willy Tarreau79e57332018-10-02 16:01:16 +02001126 4);
1127 temp->data += 4;
1128 break;
1129 case AF_INET6:
1130 memcpy(temp->area + temp->data,
Willy Tarreau9a1efe12019-07-17 17:13:50 +02001131 &((struct sockaddr_in6 *)cli_conn->src)->sin6_addr,
Willy Tarreau79e57332018-10-02 16:01:16 +02001132 16);
1133 temp->data += 16;
1134 break;
1135 default:
1136 return 0;
1137 }
1138
1139 smp->data.u.str = *temp;
1140 smp->data.type = SMP_T_BIN;
1141 return 1;
1142}
1143
1144/* Extracts the query string, which comes after the question mark '?'. If no
1145 * question mark is found, nothing is returned. Otherwise it returns a sample
1146 * of type string carrying the whole query string.
1147 */
1148static int smp_fetch_query(const struct arg *args, struct sample *smp, const char *kw, void *private)
1149{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001150 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001151 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1152 struct htx_sl *sl;
Willy Tarreau79e57332018-10-02 16:01:16 +02001153 char *ptr, *end;
1154
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001155 if (!htx)
1156 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001157
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001158 sl = http_get_stline(htx);
1159 ptr = HTX_SL_REQ_UPTR(sl);
1160 end = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
Willy Tarreau79e57332018-10-02 16:01:16 +02001161
1162 /* look up the '?' */
1163 do {
1164 if (ptr == end)
1165 return 0;
1166 } while (*ptr++ != '?');
1167
1168 smp->data.type = SMP_T_STR;
1169 smp->data.u.str.area = ptr;
1170 smp->data.u.str.data = end - ptr;
1171 smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
1172 return 1;
1173}
1174
1175static int smp_fetch_proto_http(const struct arg *args, struct sample *smp, const char *kw, void *private)
1176{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001177 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001178 struct htx *htx = smp_prefetch_htx(smp, chn, 0);
Willy Tarreau79e57332018-10-02 16:01:16 +02001179
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001180 if (!htx)
1181 return 0;
1182 smp->data.type = SMP_T_BOOL;
Willy Tarreau79e57332018-10-02 16:01:16 +02001183 smp->data.u.sint = 1;
1184 return 1;
1185}
1186
1187/* return a valid test if the current request is the first one on the connection */
1188static int smp_fetch_http_first_req(const struct arg *args, struct sample *smp, const char *kw, void *private)
1189{
Willy Tarreau79512b62020-04-29 11:52:13 +02001190 if (!smp->strm)
1191 return 0;
1192
Willy Tarreau79e57332018-10-02 16:01:16 +02001193 smp->data.type = SMP_T_BOOL;
1194 smp->data.u.sint = !(smp->strm->txn->flags & TX_NOT_FIRST);
1195 return 1;
1196}
1197
Christopher Fauleta4063562019-08-02 11:51:37 +02001198/* Fetch the authentication method if there is an Authorization header. It
1199 * relies on get_http_auth()
1200 */
1201static int smp_fetch_http_auth_type(const struct arg *args, struct sample *smp, const char *kw, void *private)
1202{
1203 struct channel *chn = SMP_REQ_CHN(smp);
1204 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1205 struct http_txn *txn;
1206
1207 if (!htx)
1208 return 0;
1209
1210 txn = smp->strm->txn;
1211 if (!get_http_auth(smp, htx))
1212 return 0;
1213
1214 switch (txn->auth.method) {
1215 case HTTP_AUTH_BASIC:
1216 smp->data.u.str.area = "Basic";
1217 smp->data.u.str.data = 5;
1218 break;
1219 case HTTP_AUTH_DIGEST:
1220 /* Unexpected because not supported */
1221 smp->data.u.str.area = "Digest";
1222 smp->data.u.str.data = 6;
1223 break;
1224 default:
1225 return 0;
1226 }
1227
1228 smp->data.type = SMP_T_STR;
1229 smp->flags = SMP_F_CONST;
1230 return 1;
1231}
1232
1233/* Fetch the user supplied if there is an Authorization header. It relies on
1234 * get_http_auth()
1235 */
1236static int smp_fetch_http_auth_user(const struct arg *args, struct sample *smp, const char *kw, void *private)
1237{
1238 struct channel *chn = SMP_REQ_CHN(smp);
1239 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1240 struct http_txn *txn;
1241
1242 if (!htx)
1243 return 0;
1244
1245 txn = smp->strm->txn;
1246 if (!get_http_auth(smp, htx))
1247 return 0;
1248
1249 smp->data.type = SMP_T_STR;
1250 smp->data.u.str.area = txn->auth.user;
1251 smp->data.u.str.data = strlen(txn->auth.user);
1252 smp->flags = SMP_F_CONST;
1253 return 1;
1254}
1255
1256/* Fetch the password supplied if there is an Authorization header. It relies on
1257 * get_http_auth()
1258 */
1259static int smp_fetch_http_auth_pass(const struct arg *args, struct sample *smp, const char *kw, void *private)
1260{
1261 struct channel *chn = SMP_REQ_CHN(smp);
1262 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1263 struct http_txn *txn;
1264
1265 if (!htx)
1266 return 0;
1267
1268 txn = smp->strm->txn;
1269 if (!get_http_auth(smp, htx))
1270 return 0;
1271
1272 smp->data.type = SMP_T_STR;
1273 smp->data.u.str.area = txn->auth.pass;
1274 smp->data.u.str.data = strlen(txn->auth.pass);
1275 smp->flags = SMP_F_CONST;
1276 return 1;
1277}
1278
Willy Tarreau79e57332018-10-02 16:01:16 +02001279/* Accepts exactly 1 argument of type userlist */
1280static int smp_fetch_http_auth(const struct arg *args, struct sample *smp, const char *kw, void *private)
1281{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001282 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001283 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
Willy Tarreau79e57332018-10-02 16:01:16 +02001284
1285 if (!args || args->type != ARGT_USR)
1286 return 0;
1287
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001288 if (!htx)
1289 return 0;
1290 if (!get_http_auth(smp, htx))
1291 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001292
1293 smp->data.type = SMP_T_BOOL;
1294 smp->data.u.sint = check_user(args->data.usr, smp->strm->txn->auth.user,
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001295 smp->strm->txn->auth.pass);
Willy Tarreau79e57332018-10-02 16:01:16 +02001296 return 1;
1297}
1298
1299/* Accepts exactly 1 argument of type userlist */
1300static int smp_fetch_http_auth_grp(const struct arg *args, struct sample *smp, const char *kw, void *private)
1301{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001302 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001303 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
Christopher Faulet89dc4992019-04-17 12:02:59 +02001304
Willy Tarreau79e57332018-10-02 16:01:16 +02001305 if (!args || args->type != ARGT_USR)
1306 return 0;
1307
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001308 if (!htx)
1309 return 0;
1310 if (!get_http_auth(smp, htx))
1311 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001312
Willy Tarreau79e57332018-10-02 16:01:16 +02001313 /* if the user does not belong to the userlist or has a wrong password,
1314 * report that it unconditionally does not match. Otherwise we return
1315 * a string containing the username.
1316 */
1317 if (!check_user(args->data.usr, smp->strm->txn->auth.user,
1318 smp->strm->txn->auth.pass))
1319 return 0;
1320
1321 /* pat_match_auth() will need the user list */
1322 smp->ctx.a[0] = args->data.usr;
1323
1324 smp->data.type = SMP_T_STR;
1325 smp->flags = SMP_F_CONST;
1326 smp->data.u.str.area = smp->strm->txn->auth.user;
1327 smp->data.u.str.data = strlen(smp->strm->txn->auth.user);
1328
1329 return 1;
1330}
1331
1332/* Fetch a captured HTTP request header. The index is the position of
1333 * the "capture" option in the configuration file
1334 */
1335static int smp_fetch_capture_req_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private)
1336{
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001337 struct proxy *fe;
Willy Tarreau79e57332018-10-02 16:01:16 +02001338 int idx;
1339
1340 if (!args || args->type != ARGT_SINT)
1341 return 0;
1342
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001343 if (!smp->strm)
1344 return 0;
1345
1346 fe = strm_fe(smp->strm);
Willy Tarreau79e57332018-10-02 16:01:16 +02001347 idx = args->data.sint;
1348
1349 if (idx > (fe->nb_req_cap - 1) || smp->strm->req_cap == NULL || smp->strm->req_cap[idx] == NULL)
1350 return 0;
1351
1352 smp->data.type = SMP_T_STR;
1353 smp->flags |= SMP_F_CONST;
1354 smp->data.u.str.area = smp->strm->req_cap[idx];
1355 smp->data.u.str.data = strlen(smp->strm->req_cap[idx]);
1356
1357 return 1;
1358}
1359
1360/* Fetch a captured HTTP response header. The index is the position of
1361 * the "capture" option in the configuration file
1362 */
1363static int smp_fetch_capture_res_hdr(const struct arg *args, struct sample *smp, const char *kw, void *private)
1364{
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001365 struct proxy *fe;
Willy Tarreau79e57332018-10-02 16:01:16 +02001366 int idx;
1367
1368 if (!args || args->type != ARGT_SINT)
1369 return 0;
1370
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001371 if (!smp->strm)
1372 return 0;
1373
1374 fe = strm_fe(smp->strm);
Willy Tarreau79e57332018-10-02 16:01:16 +02001375 idx = args->data.sint;
1376
1377 if (idx > (fe->nb_rsp_cap - 1) || smp->strm->res_cap == NULL || smp->strm->res_cap[idx] == NULL)
1378 return 0;
1379
1380 smp->data.type = SMP_T_STR;
1381 smp->flags |= SMP_F_CONST;
1382 smp->data.u.str.area = smp->strm->res_cap[idx];
1383 smp->data.u.str.data = strlen(smp->strm->res_cap[idx]);
1384
1385 return 1;
1386}
1387
1388/* Extracts the METHOD in the HTTP request, the txn->uri should be filled before the call */
1389static int smp_fetch_capture_req_method(const struct arg *args, struct sample *smp, const char *kw, void *private)
1390{
1391 struct buffer *temp;
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001392 struct http_txn *txn;
Willy Tarreau79e57332018-10-02 16:01:16 +02001393 char *ptr;
1394
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001395 if (!smp->strm)
1396 return 0;
1397
1398 txn = smp->strm->txn;
Willy Tarreau79e57332018-10-02 16:01:16 +02001399 if (!txn || !txn->uri)
1400 return 0;
1401
1402 ptr = txn->uri;
1403
1404 while (*ptr != ' ' && *ptr != '\0') /* find first space */
1405 ptr++;
1406
1407 temp = get_trash_chunk();
1408 temp->area = txn->uri;
1409 temp->data = ptr - txn->uri;
1410 smp->data.u.str = *temp;
1411 smp->data.type = SMP_T_STR;
1412 smp->flags = SMP_F_CONST;
1413
1414 return 1;
1415
1416}
1417
1418/* Extracts the path in the HTTP request, the txn->uri should be filled before the call */
1419static int smp_fetch_capture_req_uri(const struct arg *args, struct sample *smp, const char *kw, void *private)
1420{
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001421 struct http_txn *txn;
Willy Tarreau79e57332018-10-02 16:01:16 +02001422 struct ist path;
1423 const char *ptr;
1424
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001425 if (!smp->strm)
1426 return 0;
1427
1428 txn = smp->strm->txn;
Willy Tarreau79e57332018-10-02 16:01:16 +02001429 if (!txn || !txn->uri)
1430 return 0;
1431
1432 ptr = txn->uri;
1433
1434 while (*ptr != ' ' && *ptr != '\0') /* find first space */
1435 ptr++;
1436
1437 if (!*ptr)
1438 return 0;
1439
Christopher Faulet78337bb2018-11-15 14:35:18 +01001440 /* skip the first space and find space after URI */
1441 path = ist2(++ptr, 0);
1442 while (*ptr != ' ' && *ptr != '\0')
1443 ptr++;
1444 path.len = ptr - path.ptr;
Willy Tarreau79e57332018-10-02 16:01:16 +02001445
Christopher Faulet78337bb2018-11-15 14:35:18 +01001446 path = http_get_path(path);
Tim Duesterhused526372020-03-05 17:56:33 +01001447 if (!isttest(path))
Willy Tarreau79e57332018-10-02 16:01:16 +02001448 return 0;
1449
1450 smp->data.u.str.area = path.ptr;
1451 smp->data.u.str.data = path.len;
1452 smp->data.type = SMP_T_STR;
1453 smp->flags = SMP_F_CONST;
1454
1455 return 1;
1456}
1457
1458/* Retrieves the HTTP version from the request (either 1.0 or 1.1) and emits it
1459 * as a string (either "HTTP/1.0" or "HTTP/1.1").
1460 */
1461static int smp_fetch_capture_req_ver(const struct arg *args, struct sample *smp, const char *kw, void *private)
1462{
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001463 struct http_txn *txn;
1464
1465 if (!smp->strm)
1466 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001467
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001468 txn = smp->strm->txn;
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001469 if (!txn || txn->req.msg_state >= HTTP_MSG_BODY)
Willy Tarreau79e57332018-10-02 16:01:16 +02001470 return 0;
1471
1472 if (txn->req.flags & HTTP_MSGF_VER_11)
1473 smp->data.u.str.area = "HTTP/1.1";
1474 else
1475 smp->data.u.str.area = "HTTP/1.0";
1476
1477 smp->data.u.str.data = 8;
1478 smp->data.type = SMP_T_STR;
1479 smp->flags = SMP_F_CONST;
1480 return 1;
1481
1482}
1483
1484/* Retrieves the HTTP version from the response (either 1.0 or 1.1) and emits it
1485 * as a string (either "HTTP/1.0" or "HTTP/1.1").
1486 */
1487static int smp_fetch_capture_res_ver(const struct arg *args, struct sample *smp, const char *kw, void *private)
1488{
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001489 struct http_txn *txn;
1490
1491 if (!smp->strm)
1492 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001493
Willy Tarreau0898c2d2020-04-29 11:44:54 +02001494 txn = smp->strm->txn;
Christopher Faulet711ed6a2019-07-16 14:16:10 +02001495 if (!txn || txn->rsp.msg_state >= HTTP_MSG_BODY)
Willy Tarreau79e57332018-10-02 16:01:16 +02001496 return 0;
1497
1498 if (txn->rsp.flags & HTTP_MSGF_VER_11)
1499 smp->data.u.str.area = "HTTP/1.1";
1500 else
1501 smp->data.u.str.area = "HTTP/1.0";
1502
1503 smp->data.u.str.data = 8;
1504 smp->data.type = SMP_T_STR;
1505 smp->flags = SMP_F_CONST;
1506 return 1;
1507
1508}
1509
1510/* Iterate over all cookies present in a message. The context is stored in
1511 * smp->ctx.a[0] for the in-header position, smp->ctx.a[1] for the
1512 * end-of-header-value, and smp->ctx.a[2] for the hdr_ctx. Depending on
1513 * the direction, multiple cookies may be parsed on the same line or not.
1514 * The cookie name is in args and the name length in args->data.str.len.
1515 * Accepts exactly 1 argument of type string. If the input options indicate
1516 * that no iterating is desired, then only last value is fetched if any.
1517 * The returned sample is of type CSTR. Can be used to parse cookies in other
1518 * files.
1519 */
1520static int smp_fetch_cookie(const struct arg *args, struct sample *smp, const char *kw, void *private)
1521{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001522 /* possible keywords: req.cookie / cookie / cook, res.cookie / scook / set-cookie */
1523 struct channel *chn = ((kw[0] == 'c' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001524 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1525 struct http_hdr_ctx *ctx = smp->ctx.a[2];
1526 struct ist hdr;
Willy Tarreau79e57332018-10-02 16:01:16 +02001527 int occ = 0;
1528 int found = 0;
1529
1530 if (!args || args->type != ARGT_STR)
1531 return 0;
1532
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001533 if (!ctx) {
1534 /* first call */
1535 ctx = &static_http_hdr_ctx;
1536 ctx->blk = NULL;
1537 smp->ctx.a[2] = ctx;
1538 }
Willy Tarreau79e57332018-10-02 16:01:16 +02001539
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001540 if (!htx)
1541 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001542
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001543 hdr = (!(chn->flags & CF_ISRESP) ? ist("Cookie") : ist("Set-Cookie"));
Willy Tarreau79e57332018-10-02 16:01:16 +02001544
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001545 if (!occ && !(smp->opt & SMP_OPT_ITERATE))
1546 /* no explicit occurrence and single fetch => last cookie by default */
1547 occ = -1;
Willy Tarreau79e57332018-10-02 16:01:16 +02001548
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001549 /* OK so basically here, either we want only one value and it's the
1550 * last one, or we want to iterate over all of them and we fetch the
1551 * next one.
1552 */
Willy Tarreau79e57332018-10-02 16:01:16 +02001553
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001554 if (!(smp->flags & SMP_F_NOT_LAST)) {
1555 /* search for the header from the beginning, we must first initialize
1556 * the search parameters.
Willy Tarreau79e57332018-10-02 16:01:16 +02001557 */
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001558 smp->ctx.a[0] = NULL;
1559 ctx->blk = NULL;
Willy Tarreau79e57332018-10-02 16:01:16 +02001560 }
Willy Tarreau79e57332018-10-02 16:01:16 +02001561
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001562 smp->flags |= SMP_F_VOL_HDR;
1563 while (1) {
1564 /* Note: smp->ctx.a[0] == NULL every time we need to fetch a new header */
1565 if (!smp->ctx.a[0]) {
1566 if (!http_find_header(htx, hdr, ctx, 0))
1567 goto out;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001568
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001569 if (ctx->value.len < args->data.str.data + 1)
1570 continue;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001571
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001572 smp->ctx.a[0] = ctx->value.ptr;
1573 smp->ctx.a[1] = smp->ctx.a[0] + ctx->value.len;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001574 }
1575
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001576 smp->data.type = SMP_T_STR;
1577 smp->flags |= SMP_F_CONST;
1578 smp->ctx.a[0] = http_extract_cookie_value(smp->ctx.a[0], smp->ctx.a[1],
1579 args->data.str.area, args->data.str.data,
1580 (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ,
1581 &smp->data.u.str.area,
1582 &smp->data.u.str.data);
1583 if (smp->ctx.a[0]) {
1584 found = 1;
1585 if (occ >= 0) {
1586 /* one value was returned into smp->data.u.str.{str,len} */
1587 smp->flags |= SMP_F_NOT_LAST;
1588 return 1;
Willy Tarreau79e57332018-10-02 16:01:16 +02001589 }
1590 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001591 /* if we're looking for last occurrence, let's loop */
Willy Tarreau79e57332018-10-02 16:01:16 +02001592 }
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001593
Willy Tarreau79e57332018-10-02 16:01:16 +02001594 /* all cookie headers and values were scanned. If we're looking for the
1595 * last occurrence, we may return it now.
1596 */
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001597 out:
Willy Tarreau79e57332018-10-02 16:01:16 +02001598 smp->flags &= ~SMP_F_NOT_LAST;
1599 return found;
1600}
1601
Christopher Fauletc1f40dd2019-05-16 10:07:30 +02001602/* Same than smp_fetch_cookie() but only relies on the sample direction to
1603 * choose the right channel. So instead of duplicating the code, we just change
1604 * the keyword and then fallback on smp_fetch_cookie().
1605 */
1606static int smp_fetch_chn_cookie(const struct arg *args, struct sample *smp, const char *kw, void *private)
1607{
1608 kw = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ ? "req.cook" : "res.cook");
1609 return smp_fetch_cookie(args, smp, kw, private);
1610}
1611
Willy Tarreau79e57332018-10-02 16:01:16 +02001612/* Iterate over all cookies present in a request to count how many occurrences
1613 * match the name in args and args->data.str.len. If <multi> is non-null, then
1614 * multiple cookies may be parsed on the same line. The returned sample is of
1615 * type UINT. Accepts exactly 1 argument of type string.
1616 */
1617static int smp_fetch_cookie_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private)
1618{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001619 /* possible keywords: req.cook_cnt / cook_cnt, res.cook_cnt / scook_cnt */
1620 struct channel *chn = ((kw[0] == 'c' || kw[2] == 'q') ? SMP_REQ_CHN(smp) : SMP_RES_CHN(smp));
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001621 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1622 struct http_hdr_ctx ctx;
1623 struct ist hdr;
Willy Tarreau79e57332018-10-02 16:01:16 +02001624 char *val_beg, *val_end;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001625 int cnt;
Willy Tarreau79e57332018-10-02 16:01:16 +02001626
1627 if (!args || args->type != ARGT_STR)
1628 return 0;
1629
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001630 if (!htx)
1631 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001632
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001633 hdr = (!(chn->flags & CF_ISRESP) ? ist("Cookie") : ist("Set-Cookie"));
Willy Tarreau79e57332018-10-02 16:01:16 +02001634
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001635 val_end = val_beg = NULL;
1636 ctx.blk = NULL;
1637 cnt = 0;
1638 while (1) {
1639 /* Note: val_beg == NULL every time we need to fetch a new header */
1640 if (!val_beg) {
1641 if (!http_find_header(htx, hdr, &ctx, 0))
1642 break;
Willy Tarreau79e57332018-10-02 16:01:16 +02001643
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001644 if (ctx.value.len < args->data.str.data + 1)
1645 continue;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001646
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001647 val_beg = ctx.value.ptr;
1648 val_end = val_beg + ctx.value.len;
Willy Tarreau79e57332018-10-02 16:01:16 +02001649 }
1650
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001651 smp->data.type = SMP_T_STR;
1652 smp->flags |= SMP_F_CONST;
1653 while ((val_beg = http_extract_cookie_value(val_beg, val_end,
1654 args->data.str.area, args->data.str.data,
1655 (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ,
1656 &smp->data.u.str.area,
1657 &smp->data.u.str.data))) {
1658 cnt++;
Willy Tarreau79e57332018-10-02 16:01:16 +02001659 }
1660 }
1661
1662 smp->data.type = SMP_T_SINT;
1663 smp->data.u.sint = cnt;
1664 smp->flags |= SMP_F_VOL_HDR;
1665 return 1;
1666}
1667
1668/* Fetch an cookie's integer value. The integer value is returned. It
1669 * takes a mandatory argument of type string. It relies on smp_fetch_cookie().
1670 */
1671static int smp_fetch_cookie_val(const struct arg *args, struct sample *smp, const char *kw, void *private)
1672{
1673 int ret = smp_fetch_cookie(args, smp, kw, private);
1674
1675 if (ret > 0) {
1676 smp->data.type = SMP_T_SINT;
1677 smp->data.u.sint = strl2ic(smp->data.u.str.area,
1678 smp->data.u.str.data);
1679 }
1680
1681 return ret;
1682}
1683
1684/************************************************************************/
1685/* The code below is dedicated to sample fetches */
1686/************************************************************************/
1687
1688/* This scans a URL-encoded query string. It takes an optionally wrapping
1689 * string whose first contigous chunk has its beginning in ctx->a[0] and end
1690 * in ctx->a[1], and the optional second part in (ctx->a[2]..ctx->a[3]). The
1691 * pointers are updated for next iteration before leaving.
1692 */
1693static int smp_fetch_param(char delim, const char *name, int name_len, const struct arg *args, struct sample *smp, const char *kw, void *private)
1694{
1695 const char *vstart, *vend;
1696 struct buffer *temp;
1697 const char **chunks = (const char **)smp->ctx.a;
1698
1699 if (!http_find_next_url_param(chunks, name, name_len,
1700 &vstart, &vend, delim))
1701 return 0;
1702
1703 /* Create sample. If the value is contiguous, return the pointer as CONST,
1704 * if the value is wrapped, copy-it in a buffer.
1705 */
1706 smp->data.type = SMP_T_STR;
1707 if (chunks[2] &&
1708 vstart >= chunks[0] && vstart <= chunks[1] &&
1709 vend >= chunks[2] && vend <= chunks[3]) {
1710 /* Wrapped case. */
1711 temp = get_trash_chunk();
1712 memcpy(temp->area, vstart, chunks[1] - vstart);
1713 memcpy(temp->area + ( chunks[1] - vstart ), chunks[2],
1714 vend - chunks[2]);
1715 smp->data.u.str.area = temp->area;
1716 smp->data.u.str.data = ( chunks[1] - vstart ) + ( vend - chunks[2] );
1717 } else {
1718 /* Contiguous case. */
1719 smp->data.u.str.area = (char *)vstart;
1720 smp->data.u.str.data = vend - vstart;
1721 smp->flags = SMP_F_VOL_1ST | SMP_F_CONST;
1722 }
1723
1724 /* Update context, check wrapping. */
1725 chunks[0] = vend;
1726 if (chunks[2] && vend >= chunks[2] && vend <= chunks[3]) {
1727 chunks[1] = chunks[3];
1728 chunks[2] = NULL;
1729 }
1730
1731 if (chunks[0] < chunks[1])
1732 smp->flags |= SMP_F_NOT_LAST;
1733
1734 return 1;
1735}
1736
1737/* This function iterates over each parameter of the query string. It uses
1738 * ctx->a[0] and ctx->a[1] to store the beginning and end of the current
1739 * parameter. Since it uses smp_fetch_param(), ctx->a[2..3] are both NULL.
1740 * An optional parameter name is passed in args[0], otherwise any parameter is
1741 * considered. It supports an optional delimiter argument for the beginning of
1742 * the string in args[1], which defaults to "?".
1743 */
1744static int smp_fetch_url_param(const struct arg *args, struct sample *smp, const char *kw, void *private)
1745{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001746 struct channel *chn = SMP_REQ_CHN(smp);
Willy Tarreau79e57332018-10-02 16:01:16 +02001747 char delim = '?';
1748 const char *name;
1749 int name_len;
1750
1751 if (!args ||
1752 (args[0].type && args[0].type != ARGT_STR) ||
1753 (args[1].type && args[1].type != ARGT_STR))
1754 return 0;
1755
1756 name = "";
1757 name_len = 0;
1758 if (args->type == ARGT_STR) {
1759 name = args->data.str.area;
1760 name_len = args->data.str.data;
1761 }
1762
1763 if (args[1].type)
1764 delim = *args[1].data.str.area;
1765
1766 if (!smp->ctx.a[0]) { // first call, find the query string
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001767 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1768 struct htx_sl *sl;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001769
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001770 if (!htx)
1771 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001772
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001773 sl = http_get_stline(htx);
1774 smp->ctx.a[0] = http_find_param_list(HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl), delim);
1775 if (!smp->ctx.a[0])
1776 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001777
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001778 smp->ctx.a[1] = HTX_SL_REQ_UPTR(sl) + HTX_SL_REQ_ULEN(sl);
Willy Tarreau79e57332018-10-02 16:01:16 +02001779
1780 /* Assume that the context is filled with NULL pointer
1781 * before the first call.
1782 * smp->ctx.a[2] = NULL;
1783 * smp->ctx.a[3] = NULL;
1784 */
1785 }
1786
1787 return smp_fetch_param(delim, name, name_len, args, smp, kw, private);
1788}
1789
1790/* This function iterates over each parameter of the body. This requires
1791 * that the body has been waited for using http-buffer-request. It uses
1792 * ctx->a[0] and ctx->a[1] to store the beginning and end of the first
1793 * contigous part of the body, and optionally ctx->a[2..3] to reference the
1794 * optional second part if the body wraps at the end of the buffer. An optional
1795 * parameter name is passed in args[0], otherwise any parameter is considered.
1796 */
1797static int smp_fetch_body_param(const struct arg *args, struct sample *smp, const char *kw, void *private)
1798{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001799 struct channel *chn = SMP_REQ_CHN(smp);
Willy Tarreau79e57332018-10-02 16:01:16 +02001800 const char *name;
1801 int name_len;
1802
1803 if (!args || (args[0].type && args[0].type != ARGT_STR))
1804 return 0;
1805
1806 name = "";
1807 name_len = 0;
1808 if (args[0].type == ARGT_STR) {
1809 name = args[0].data.str.area;
1810 name_len = args[0].data.str.data;
1811 }
1812
1813 if (!smp->ctx.a[0]) { // first call, find the query string
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001814 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1815 struct buffer *temp;
1816 int32_t pos;
Willy Tarreau79e57332018-10-02 16:01:16 +02001817
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001818 if (!htx)
1819 return 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001820
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001821 temp = get_trash_chunk();
1822 for (pos = htx_get_first(htx); pos != -1; pos = htx_get_next(htx, pos)) {
1823 struct htx_blk *blk = htx_get_blk(htx, pos);
1824 enum htx_blk_type type = htx_get_blk_type(blk);
Willy Tarreau79e57332018-10-02 16:01:16 +02001825
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001826 if (type == HTX_BLK_EOM || type == HTX_BLK_TLR || type == HTX_BLK_EOT)
1827 break;
1828 if (type == HTX_BLK_DATA) {
Christopher Faulet53a899b2019-10-08 16:38:42 +02001829 if (!h1_format_htx_data(htx_get_blk_value(htx, blk), temp, 0))
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001830 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001831 }
Willy Tarreau79e57332018-10-02 16:01:16 +02001832 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001833
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001834 smp->ctx.a[0] = temp->area;
1835 smp->ctx.a[1] = temp->area + temp->data;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001836
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001837 /* Assume that the context is filled with NULL pointer
1838 * before the first call.
1839 * smp->ctx.a[2] = NULL;
1840 * smp->ctx.a[3] = NULL;
1841 */
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001842
Willy Tarreau79e57332018-10-02 16:01:16 +02001843 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001844
Willy Tarreau79e57332018-10-02 16:01:16 +02001845 return smp_fetch_param('&', name, name_len, args, smp, kw, private);
1846}
1847
1848/* Return the signed integer value for the specified url parameter (see url_param
1849 * above).
1850 */
1851static int smp_fetch_url_param_val(const struct arg *args, struct sample *smp, const char *kw, void *private)
1852{
1853 int ret = smp_fetch_url_param(args, smp, kw, private);
1854
1855 if (ret > 0) {
1856 smp->data.type = SMP_T_SINT;
1857 smp->data.u.sint = strl2ic(smp->data.u.str.area,
1858 smp->data.u.str.data);
1859 }
1860
1861 return ret;
1862}
1863
1864/* This produces a 32-bit hash of the concatenation of the first occurrence of
1865 * the Host header followed by the path component if it begins with a slash ('/').
1866 * This means that '*' will not be added, resulting in exactly the first Host
1867 * entry. If no Host header is found, then the path is used. The resulting value
1868 * is hashed using the url hash followed by a full avalanche hash and provides a
1869 * 32-bit integer value. This fetch is useful for tracking per-URL activity on
1870 * high-traffic sites without having to store whole paths.
1871 * this differs from the base32 functions in that it includes the url parameters
1872 * as well as the path
1873 */
1874static int smp_fetch_url32(const struct arg *args, struct sample *smp, const char *kw, void *private)
1875{
Christopher Faulet89dc4992019-04-17 12:02:59 +02001876 struct channel *chn = SMP_REQ_CHN(smp);
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001877 struct htx *htx = smp_prefetch_htx(smp, chn, 1);
1878 struct http_hdr_ctx ctx;
1879 struct htx_sl *sl;
1880 struct ist path;
Willy Tarreau79e57332018-10-02 16:01:16 +02001881 unsigned int hash = 0;
Willy Tarreau79e57332018-10-02 16:01:16 +02001882
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001883 if (!htx)
1884 return 0;
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001885
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001886 ctx.blk = NULL;
1887 if (http_find_header(htx, ist("Host"), &ctx, 1)) {
1888 /* OK we have the header value in ctx.value */
1889 while (ctx.value.len--)
1890 hash = *(ctx.value.ptr++) + (hash << 6) + (hash << 16) - hash;
Willy Tarreau79e57332018-10-02 16:01:16 +02001891 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001892
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001893 /* now retrieve the path */
1894 sl = http_get_stline(htx);
1895 path = http_get_path(htx_sl_req_uri(sl));
Christopher Faulet6d1dd462019-07-15 14:36:03 +02001896 if (path.len && *(path.ptr) == '/') {
1897 while (path.len--)
1898 hash = *(path.ptr++) + (hash << 6) + (hash << 16) - hash;
Willy Tarreau79e57332018-10-02 16:01:16 +02001899 }
Christopher Faulet311c7ea2018-10-24 21:41:55 +02001900
Willy Tarreau79e57332018-10-02 16:01:16 +02001901 hash = full_hash(hash);
1902
1903 smp->data.type = SMP_T_SINT;
1904 smp->data.u.sint = hash;
1905 smp->flags = SMP_F_VOL_1ST;
1906 return 1;
1907}
1908
1909/* This concatenates the source address with the 32-bit hash of the Host and
1910 * URL as returned by smp_fetch_base32(). The idea is to have per-source and
1911 * per-url counters. The result is a binary block from 8 to 20 bytes depending
1912 * on the source address length. The URL hash is stored before the address so
1913 * that in environments where IPv6 is insignificant, truncating the output to
1914 * 8 bytes would still work.
1915 */
1916static int smp_fetch_url32_src(const struct arg *args, struct sample *smp, const char *kw, void *private)
1917{
1918 struct buffer *temp;
1919 struct connection *cli_conn = objt_conn(smp->sess->origin);
1920
Willy Tarreaucd7ca792019-07-17 16:57:03 +02001921 if (!cli_conn || !conn_get_src(cli_conn))
Willy Tarreau79e57332018-10-02 16:01:16 +02001922 return 0;
1923
1924 if (!smp_fetch_url32(args, smp, kw, private))
1925 return 0;
1926
1927 temp = get_trash_chunk();
1928 *(unsigned int *) temp->area = htonl(smp->data.u.sint);
1929 temp->data += sizeof(unsigned int);
1930
Willy Tarreau9a1efe12019-07-17 17:13:50 +02001931 switch (cli_conn->src->ss_family) {
Willy Tarreau79e57332018-10-02 16:01:16 +02001932 case AF_INET:
1933 memcpy(temp->area + temp->data,
Willy Tarreau9a1efe12019-07-17 17:13:50 +02001934 &((struct sockaddr_in *)cli_conn->src)->sin_addr,
Willy Tarreau79e57332018-10-02 16:01:16 +02001935 4);
1936 temp->data += 4;
1937 break;
1938 case AF_INET6:
1939 memcpy(temp->area + temp->data,
Willy Tarreau9a1efe12019-07-17 17:13:50 +02001940 &((struct sockaddr_in6 *)cli_conn->src)->sin6_addr,
Willy Tarreau79e57332018-10-02 16:01:16 +02001941 16);
1942 temp->data += 16;
1943 break;
1944 default:
1945 return 0;
1946 }
1947
1948 smp->data.u.str = *temp;
1949 smp->data.type = SMP_T_BIN;
1950 return 1;
1951}
1952
1953/************************************************************************/
1954/* Other utility functions */
1955/************************************************************************/
1956
1957/* This function is used to validate the arguments passed to any "hdr" fetch
1958 * keyword. These keywords support an optional positive or negative occurrence
1959 * number. We must ensure that the number is greater than -MAX_HDR_HISTORY. It
1960 * is assumed that the types are already the correct ones. Returns 0 on error,
1961 * non-zero if OK. If <err> is not NULL, it will be filled with a pointer to an
1962 * error message in case of error, that the caller is responsible for freeing.
1963 * The initial location must either be freeable or NULL.
1964 * Note: this function's pointer is checked from Lua.
1965 */
1966int val_hdr(struct arg *arg, char **err_msg)
1967{
1968 if (arg && arg[1].type == ARGT_SINT && arg[1].data.sint < -MAX_HDR_HISTORY) {
1969 memprintf(err_msg, "header occurrence must be >= %d", -MAX_HDR_HISTORY);
1970 return 0;
1971 }
1972 return 1;
1973}
1974
1975/************************************************************************/
1976/* All supported sample fetch keywords must be declared here. */
1977/************************************************************************/
1978
1979/* Note: must not be declared <const> as its list will be overwritten */
1980static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
1981 { "base", smp_fetch_base, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
1982 { "base32", smp_fetch_base32, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV },
1983 { "base32+src", smp_fetch_base32_src, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV },
1984
1985 /* capture are allocated and are permanent in the stream */
1986 { "capture.req.hdr", smp_fetch_capture_req_hdr, ARG1(1,SINT), NULL, SMP_T_STR, SMP_USE_HRQHP },
1987
1988 /* retrieve these captures from the HTTP logs */
1989 { "capture.req.method", smp_fetch_capture_req_method, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
1990 { "capture.req.uri", smp_fetch_capture_req_uri, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
1991 { "capture.req.ver", smp_fetch_capture_req_ver, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
1992
1993 { "capture.res.hdr", smp_fetch_capture_res_hdr, ARG1(1,SINT), NULL, SMP_T_STR, SMP_USE_HRSHP },
1994 { "capture.res.ver", smp_fetch_capture_res_ver, 0, NULL, SMP_T_STR, SMP_USE_HRQHP },
1995
1996 /* cookie is valid in both directions (eg: for "stick ...") but cook*
1997 * are only here to match the ACL's name, are request-only and are used
1998 * for ACL compatibility only.
1999 */
2000 { "cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
Christopher Fauletc1f40dd2019-05-16 10:07:30 +02002001 { "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 +02002002 { "cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2003 { "cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2004
2005 /* hdr is valid in both directions (eg: for "stick ...") but hdr_* are
2006 * only here to match the ACL's name, are request-only and are used for
2007 * ACL compatibility only.
2008 */
Christopher Fauletc1f40dd2019-05-16 10:07:30 +02002009 { "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 +02002010 { "hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2011 { "hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRQHV },
2012 { "hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRQHV },
2013
Christopher Fauleta4063562019-08-02 11:51:37 +02002014 { "http_auth_type", smp_fetch_http_auth_type, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2015 { "http_auth_user", smp_fetch_http_auth_user, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2016 { "http_auth_pass", smp_fetch_http_auth_pass, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
Willy Tarreau79e57332018-10-02 16:01:16 +02002017 { "http_auth", smp_fetch_http_auth, ARG1(1,USR), NULL, SMP_T_BOOL, SMP_USE_HRQHV },
2018 { "http_auth_group", smp_fetch_http_auth_grp, ARG1(1,USR), NULL, SMP_T_STR, SMP_USE_HRQHV },
2019 { "http_first_req", smp_fetch_http_first_req, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP },
2020 { "method", smp_fetch_meth, 0, NULL, SMP_T_METH, SMP_USE_HRQHP },
2021 { "path", smp_fetch_path, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2022 { "query", smp_fetch_query, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2023
2024 /* HTTP protocol on the request path */
2025 { "req.proto_http", smp_fetch_proto_http, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP },
2026 { "req_proto_http", smp_fetch_proto_http, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHP },
2027
2028 /* HTTP version on the request path */
2029 { "req.ver", smp_fetch_rqver, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2030 { "req_ver", smp_fetch_rqver, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2031
2032 { "req.body", smp_fetch_body, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV },
2033 { "req.body_len", smp_fetch_body_len, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV },
2034 { "req.body_size", smp_fetch_body_size, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV },
2035 { "req.body_param", smp_fetch_body_param, ARG1(0,STR), NULL, SMP_T_BIN, SMP_USE_HRQHV },
2036
2037 { "req.hdrs", smp_fetch_hdrs, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV },
2038 { "req.hdrs_bin", smp_fetch_hdrs_bin, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV },
2039
2040 /* HTTP version on the response path */
2041 { "res.ver", smp_fetch_stver, 0, NULL, SMP_T_STR, SMP_USE_HRSHV },
2042 { "resp_ver", smp_fetch_stver, 0, NULL, SMP_T_STR, SMP_USE_HRSHV },
2043
2044 /* explicit req.{cook,hdr} are used to force the fetch direction to be request-only */
2045 { "req.cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
2046 { "req.cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2047 { "req.cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2048
2049 { "req.fhdr", smp_fetch_fhdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV },
2050 { "req.fhdr_cnt", smp_fetch_fhdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2051 { "req.hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRQHV },
2052 { "req.hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2053 { "req.hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRQHV },
2054 { "req.hdr_names", smp_fetch_hdr_names, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
2055 { "req.hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRQHV },
2056
2057 /* explicit req.{cook,hdr} are used to force the fetch direction to be response-only */
2058 { "res.cook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV },
2059 { "res.cook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2060 { "res.cook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2061
2062 { "res.fhdr", smp_fetch_fhdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV },
2063 { "res.fhdr_cnt", smp_fetch_fhdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2064 { "res.hdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV },
2065 { "res.hdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2066 { "res.hdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRSHV },
2067 { "res.hdr_names", smp_fetch_hdr_names, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV },
2068 { "res.hdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRSHV },
2069
2070 /* scook is valid only on the response and is used for ACL compatibility */
2071 { "scook", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV },
2072 { "scook_cnt", smp_fetch_cookie_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2073 { "scook_val", smp_fetch_cookie_val, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2074 { "set-cookie", smp_fetch_cookie, ARG1(0,STR), NULL, SMP_T_STR, SMP_USE_HRSHV }, /* deprecated */
2075
2076 /* shdr is valid only on the response and is used for ACL compatibility */
2077 { "shdr", smp_fetch_hdr, ARG2(0,STR,SINT), val_hdr, SMP_T_STR, SMP_USE_HRSHV },
2078 { "shdr_cnt", smp_fetch_hdr_cnt, ARG1(0,STR), NULL, SMP_T_SINT, SMP_USE_HRSHV },
2079 { "shdr_ip", smp_fetch_hdr_ip, ARG2(0,STR,SINT), val_hdr, SMP_T_IPV4, SMP_USE_HRSHV },
2080 { "shdr_val", smp_fetch_hdr_val, ARG2(0,STR,SINT), val_hdr, SMP_T_SINT, SMP_USE_HRSHV },
2081
2082 { "status", smp_fetch_stcode, 0, NULL, SMP_T_SINT, SMP_USE_HRSHP },
2083 { "unique-id", smp_fetch_uniqueid, 0, NULL, SMP_T_STR, SMP_SRC_L4SRV },
2084 { "url", smp_fetch_url, 0, NULL, SMP_T_STR, SMP_USE_HRQHV },
2085 { "url32", smp_fetch_url32, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV },
2086 { "url32+src", smp_fetch_url32_src, 0, NULL, SMP_T_BIN, SMP_USE_HRQHV },
2087 { "url_ip", smp_fetch_url_ip, 0, NULL, SMP_T_IPV4, SMP_USE_HRQHV },
2088 { "url_port", smp_fetch_url_port, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV },
2089 { "url_param", smp_fetch_url_param, ARG2(0,STR,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
2090 { "urlp" , smp_fetch_url_param, ARG2(0,STR,STR), NULL, SMP_T_STR, SMP_USE_HRQHV },
2091 { "urlp_val", smp_fetch_url_param_val, ARG2(0,STR,STR), NULL, SMP_T_SINT, SMP_USE_HRQHV },
2092 { /* END */ },
2093}};
2094
Willy Tarreau0108d902018-11-25 19:14:37 +01002095INITCALL1(STG_REGISTER, sample_register_fetches, &sample_fetch_keywords);
Willy Tarreau79e57332018-10-02 16:01:16 +02002096
2097/*
2098 * Local variables:
2099 * c-indent-level: 8
2100 * c-basic-offset: 8
2101 * End:
2102 */