blob: accfa19e2b4ad7e10dac4de50ebda84ffa4dd285 [file] [log] [blame]
Christopher Faulet47596d32018-10-22 09:17:28 +02001/*
2 * Functions to manipulate HTTP messages using the internal representation.
3 *
4 * Copyright (C) 2018 HAProxy Technologies, Christopher Faulet <cfaulet@haproxy.com>
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 */
Christopher Faulet5031ef52020-01-15 11:22:07 +010012#include <sys/types.h>
13#include <sys/stat.h>
14#include <fcntl.h>
15#include <unistd.h>
16
17#include <types/global.h>
Christopher Faulet47596d32018-10-22 09:17:28 +020018
19#include <common/config.h>
Christopher Faulet29f17582019-05-23 11:03:26 +020020#include <common/debug.h>
Christopher Fauleta7b677c2018-11-29 16:48:49 +010021#include <common/cfgparse.h>
Willy Tarreauafba57a2018-12-11 13:44:24 +010022#include <common/h1.h>
Christopher Faulet47596d32018-10-22 09:17:28 +020023#include <common/http.h>
Willy Tarreaub96b77e2018-12-11 10:22:41 +010024#include <common/htx.h>
Christopher Faulet47596d32018-10-22 09:17:28 +020025
Christopher Faulet29f72842019-12-11 15:52:32 +010026#include <proto/arg.h>
Christopher Faulet47596d32018-10-22 09:17:28 +020027#include <proto/http_htx.h>
Christopher Faulet29f72842019-12-11 15:52:32 +010028#include <proto/http_fetch.h>
29#include <proto/sample.h>
Christopher Faulet47596d32018-10-22 09:17:28 +020030
Christopher Fauletf7346382019-07-17 22:02:08 +020031struct buffer http_err_chunks[HTTP_ERR_SIZE];
Christopher Faulet58857752020-01-15 15:19:50 +010032struct eb_root http_error_messages = EB_ROOT;
Christopher Faulet35cd81d2020-01-15 11:22:56 +010033struct list http_errors_list = LIST_HEAD_INIT(http_errors_list);
Christopher Fauleta7b677c2018-11-29 16:48:49 +010034
Christopher Faulet76edc0f2020-01-13 15:52:01 +010035/* The declaration of an errorfiles/errorfile directives. Used during config
36 * parsing only. */
37struct conf_errors {
38 char type; /* directive type (0: errorfiles, 1: errorfile) */
39 union {
40 struct {
41 int status; /* the status code associated to this error */
42 struct buffer *msg; /* the HTX error message */
43 } errorfile; /* describe an "errorfile" directive */
44 struct {
45 char *name; /* the http-errors section name */
46 char status[HTTP_ERR_SIZE]; /* list of status to import (0: ignore, 1: implicit import, 2: explicit import) */
47 } errorfiles; /* describe an "errorfiles" directive */
48 } info;
49
50 char *file; /* file where the directive appears */
51 int line; /* line where the directive appears */
52
53 struct list list; /* next conf_errors */
54};
55
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +020056static int http_update_authority(struct htx *htx, struct htx_sl *sl, const struct ist host);
57static int http_update_host(struct htx *htx, struct htx_sl *sl, const struct ist uri);
58
Christopher Faulet297fbb42019-05-13 14:41:27 +020059/* Returns the next unporocessed start line in the HTX message. It returns NULL
Christopher Faulet29f17582019-05-23 11:03:26 +020060 * if the start-line is undefined (first == -1). Otherwise, it returns the
Christopher Faulet297fbb42019-05-13 14:41:27 +020061 * pointer on the htx_sl structure.
Christopher Faulet47596d32018-10-22 09:17:28 +020062 */
Christopher Faulet297fbb42019-05-13 14:41:27 +020063struct htx_sl *http_get_stline(struct htx *htx)
Christopher Faulet47596d32018-10-22 09:17:28 +020064{
Christopher Faulet297fbb42019-05-13 14:41:27 +020065 struct htx_blk *blk;
Christopher Faulet573fe732018-11-28 16:55:12 +010066
Christopher Faulet29f17582019-05-23 11:03:26 +020067 BUG_ON(htx->first == -1);
68 blk = htx_get_first_blk(htx);
Christopher Faulet297fbb42019-05-13 14:41:27 +020069 if (!blk)
70 return NULL;
Christopher Faulet29f17582019-05-23 11:03:26 +020071 BUG_ON(htx_get_blk_type(blk) != HTX_BLK_REQ_SL && htx_get_blk_type(blk) != HTX_BLK_RES_SL);
Christopher Faulet297fbb42019-05-13 14:41:27 +020072 return htx_get_blk_ptr(htx, blk);
Christopher Faulet47596d32018-10-22 09:17:28 +020073}
74
75/* Finds the first or next occurrence of header <name> in the HTX message <htx>
76 * using the context <ctx>. This structure holds everything necessary to use the
77 * header and find next occurrence. If its <blk> member is NULL, the header is
78 * searched from the beginning. Otherwise, the next occurrence is returned. The
79 * function returns 1 when it finds a value, and 0 when there is no more. It is
80 * designed to work with headers defined as comma-separated lists. If <full> is
81 * set, it works on full-line headers in whose comma is not a delimiter but is
82 * part of the syntax. A special case, if ctx->value is NULL when searching for
83 * a new values of a header, the current header is rescanned. This allows
84 * rescanning after a header deletion.
85 */
86int http_find_header(const struct htx *htx, const struct ist name,
87 struct http_hdr_ctx *ctx, int full)
88{
89 struct htx_blk *blk = ctx->blk;
90 struct ist n, v;
91 enum htx_blk_type type;
Christopher Faulet47596d32018-10-22 09:17:28 +020092
93 if (blk) {
94 char *p;
95
Christopher Faulet47596d32018-10-22 09:17:28 +020096 if (!ctx->value.ptr)
97 goto rescan_hdr;
98 if (full)
99 goto next_blk;
100 v = htx_get_blk_value(htx, blk);
101 p = ctx->value.ptr + ctx->value.len + ctx->lws_after;
102 v.len -= (p - v.ptr);
103 v.ptr = p;
104 if (!v.len)
105 goto next_blk;
106 /* Skip comma */
107 if (*(v.ptr) == ',') {
108 v.ptr++;
109 v.len--;
110 }
111
112 goto return_hdr;
113 }
114
Christopher Faulet192c6a22019-06-11 16:32:24 +0200115 if (htx_is_empty(htx))
Christopher Faulet47596d32018-10-22 09:17:28 +0200116 return 0;
117
Christopher Fauleta3f15502019-05-13 15:27:23 +0200118 for (blk = htx_get_first_blk(htx); blk; blk = htx_get_next_blk(htx, blk)) {
Christopher Faulet47596d32018-10-22 09:17:28 +0200119 rescan_hdr:
Christopher Faulet47596d32018-10-22 09:17:28 +0200120 type = htx_get_blk_type(blk);
Christopher Faulet573fe732018-11-28 16:55:12 +0100121 if (type == HTX_BLK_EOH || type == HTX_BLK_EOM)
122 break;
Christopher Faulet47596d32018-10-22 09:17:28 +0200123 if (type != HTX_BLK_HDR)
Christopher Faulet28f29c72019-04-30 17:55:45 +0200124 continue;
Christopher Faulet47596d32018-10-22 09:17:28 +0200125 if (name.len) {
126 /* If no name was passed, we want any header. So skip the comparison */
127 n = htx_get_blk_name(htx, blk);
128 if (!isteqi(n, name))
129 goto next_blk;
130 }
131 v = htx_get_blk_value(htx, blk);
132
133 return_hdr:
134 ctx->lws_before = 0;
135 ctx->lws_after = 0;
136 while (v.len && HTTP_IS_LWS(*v.ptr)) {
137 v.ptr++;
138 v.len--;
139 ctx->lws_before++;
140 }
141 if (!full)
142 v.len = http_find_hdr_value_end(v.ptr, v.ptr + v.len) - v.ptr;
143 while (v.len && HTTP_IS_LWS(*(v.ptr + v.len - 1))) {
144 v.len--;
145 ctx->lws_after++;
146 }
Christopher Faulet47596d32018-10-22 09:17:28 +0200147 ctx->blk = blk;
148 ctx->value = v;
149 return 1;
150
151 next_blk:
Christopher Faulet28f29c72019-04-30 17:55:45 +0200152 ;
Christopher Faulet47596d32018-10-22 09:17:28 +0200153 }
154
155 ctx->blk = NULL;
156 ctx->value = ist("");
157 ctx->lws_before = ctx->lws_after = 0;
158 return 0;
159}
160
161/* Adds a header block int the HTX message <htx>, just before the EOH block. It
162 * returns 1 on success, otherwise it returns 0.
163 */
164int http_add_header(struct htx *htx, const struct ist n, const struct ist v)
165{
166 struct htx_blk *blk;
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200167 struct htx_sl *sl;
Christopher Faulet47596d32018-10-22 09:17:28 +0200168 enum htx_blk_type type = htx_get_tail_type(htx);
169 int32_t prev;
170
171 blk = htx_add_header(htx, n, v);
172 if (!blk)
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200173 goto fail;
Christopher Faulet47596d32018-10-22 09:17:28 +0200174
175 if (unlikely(type < HTX_BLK_EOH))
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200176 goto end;
Christopher Faulet47596d32018-10-22 09:17:28 +0200177
178 /* <blk> is the head, swap it iteratively with its predecessor to place
179 * it just before the end-of-header block. So blocks remains ordered. */
Christopher Faulet29f17582019-05-23 11:03:26 +0200180 for (prev = htx_get_prev(htx, htx->tail); prev != htx->first; prev = htx_get_prev(htx, prev)) {
Christopher Faulet47596d32018-10-22 09:17:28 +0200181 struct htx_blk *pblk = htx_get_blk(htx, prev);
182 enum htx_blk_type type = htx_get_blk_type(pblk);
183
184 /* Swap .addr and .info fields */
185 blk->addr ^= pblk->addr; pblk->addr ^= blk->addr; blk->addr ^= pblk->addr;
186 blk->info ^= pblk->info; pblk->info ^= blk->info; blk->info ^= pblk->info;
187
188 if (blk->addr == pblk->addr)
189 blk->addr += htx_get_blksz(pblk);
Christopher Faulet47596d32018-10-22 09:17:28 +0200190
191 /* Stop when end-of-header is reached */
192 if (type == HTX_BLK_EOH)
193 break;
194
195 blk = pblk;
196 }
Christopher Faulet05aab642019-04-11 13:43:57 +0200197
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200198 end:
199 sl = http_get_stline(htx);
200 if (sl && (sl->flags & HTX_SL_F_HAS_AUTHORITY) && isteq(n, ist("host"))) {
201 if (!http_update_authority(htx, sl, v))
202 goto fail;
203 }
Christopher Faulet47596d32018-10-22 09:17:28 +0200204 return 1;
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200205
206 fail:
207 return 0;
Christopher Faulet47596d32018-10-22 09:17:28 +0200208}
209
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100210/* Replaces parts of the start-line of the HTX message <htx>. It returns 1 on
Christopher Faulet29f17582019-05-23 11:03:26 +0200211 * success, otherwise it returns 0.
Christopher Faulet47596d32018-10-22 09:17:28 +0200212 */
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100213int http_replace_stline(struct htx *htx, const struct ist p1, const struct ist p2, const struct ist p3)
Christopher Faulet47596d32018-10-22 09:17:28 +0200214{
Christopher Faulet7b7d5072019-05-13 15:22:59 +0200215 struct htx_blk *blk;
Christopher Faulet47596d32018-10-22 09:17:28 +0200216
Christopher Faulet29f17582019-05-23 11:03:26 +0200217 blk = htx_get_first_blk(htx);
218 if (!blk || !htx_replace_stline(htx, blk, p1, p2, p3))
Christopher Faulet7b7d5072019-05-13 15:22:59 +0200219 return 0;
220 return 1;
Christopher Faulet47596d32018-10-22 09:17:28 +0200221}
222
Christopher Faulete010c802018-10-24 10:36:45 +0200223/* Replace the request method in the HTX message <htx> by <meth>. It returns 1
224 * on success, otherwise 0.
225 */
226int http_replace_req_meth(struct htx *htx, const struct ist meth)
227{
228 struct buffer *temp = get_trash_chunk();
Christopher Faulet297fbb42019-05-13 14:41:27 +0200229 struct htx_sl *sl = http_get_stline(htx);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100230 struct ist uri, vsn;
Christopher Faulete010c802018-10-24 10:36:45 +0200231
Willy Tarreaucdce54c2019-02-12 12:02:27 +0100232 if (!sl)
233 return 0;
234
Christopher Faulete010c802018-10-24 10:36:45 +0200235 /* Start by copying old uri and version */
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100236 chunk_memcat(temp, HTX_SL_REQ_UPTR(sl), HTX_SL_REQ_ULEN(sl)); /* uri */
237 uri = ist2(temp->area, HTX_SL_REQ_ULEN(sl));
Christopher Faulete010c802018-10-24 10:36:45 +0200238
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100239 chunk_memcat(temp, HTX_SL_REQ_VPTR(sl), HTX_SL_REQ_VLEN(sl)); /* vsn */
240 vsn = ist2(temp->area + uri.len, HTX_SL_REQ_VLEN(sl));
Christopher Faulete010c802018-10-24 10:36:45 +0200241
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100242 /* create the new start line */
243 sl->info.req.meth = find_http_meth(meth.ptr, meth.len);
244 return http_replace_stline(htx, meth, uri, vsn);
Christopher Faulete010c802018-10-24 10:36:45 +0200245}
246
247/* Replace the request uri in the HTX message <htx> by <uri>. It returns 1 on
248 * success, otherwise 0.
249 */
250int http_replace_req_uri(struct htx *htx, const struct ist uri)
251{
252 struct buffer *temp = get_trash_chunk();
Christopher Faulet297fbb42019-05-13 14:41:27 +0200253 struct htx_sl *sl = http_get_stline(htx);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100254 struct ist meth, vsn;
Christopher Faulete010c802018-10-24 10:36:45 +0200255
Willy Tarreaucdce54c2019-02-12 12:02:27 +0100256 if (!sl)
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200257 goto fail;
Willy Tarreaucdce54c2019-02-12 12:02:27 +0100258
Christopher Faulete010c802018-10-24 10:36:45 +0200259 /* Start by copying old method and version */
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100260 chunk_memcat(temp, HTX_SL_REQ_MPTR(sl), HTX_SL_REQ_MLEN(sl)); /* meth */
261 meth = ist2(temp->area, HTX_SL_REQ_MLEN(sl));
Christopher Faulete010c802018-10-24 10:36:45 +0200262
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100263 chunk_memcat(temp, HTX_SL_REQ_VPTR(sl), HTX_SL_REQ_VLEN(sl)); /* vsn */
264 vsn = ist2(temp->area + meth.len, HTX_SL_REQ_VLEN(sl));
Christopher Faulete010c802018-10-24 10:36:45 +0200265
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100266 /* create the new start line */
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200267 if (!http_replace_stline(htx, meth, uri, vsn))
268 goto fail;
269
270 sl = http_get_stline(htx);
271 if (!http_update_host(htx, sl, uri))
272 goto fail;
273
274 return 1;
275 fail:
276 return 0;
Christopher Faulete010c802018-10-24 10:36:45 +0200277}
278
279/* Replace the request path in the HTX message <htx> by <path>. The host part
280 * and the query string are preserved. It returns 1 on success, otherwise 0.
281 */
282int http_replace_req_path(struct htx *htx, const struct ist path)
283{
284 struct buffer *temp = get_trash_chunk();
Christopher Faulet297fbb42019-05-13 14:41:27 +0200285 struct htx_sl *sl = http_get_stline(htx);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100286 struct ist meth, uri, vsn, p;
Christopher Faulete010c802018-10-24 10:36:45 +0200287 size_t plen = 0;
288
Willy Tarreaucdce54c2019-02-12 12:02:27 +0100289 if (!sl)
290 return 0;
291
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100292 uri = htx_sl_req_uri(sl);
293 p = http_get_path(uri);
Christopher Faulete010c802018-10-24 10:36:45 +0200294 if (!p.ptr)
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100295 p = uri;
Christopher Faulete010c802018-10-24 10:36:45 +0200296 while (plen < p.len && *(p.ptr + plen) != '?')
297 plen++;
298
299 /* Start by copying old method and version and create the new uri */
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100300 chunk_memcat(temp, HTX_SL_REQ_MPTR(sl), HTX_SL_REQ_MLEN(sl)); /* meth */
301 meth = ist2(temp->area, HTX_SL_REQ_MLEN(sl));
Christopher Faulete010c802018-10-24 10:36:45 +0200302
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100303 chunk_memcat(temp, HTX_SL_REQ_VPTR(sl), HTX_SL_REQ_VLEN(sl)); /* vsn */
304 vsn = ist2(temp->area + meth.len, HTX_SL_REQ_VLEN(sl));
305
306 chunk_memcat(temp, uri.ptr, p.ptr - uri.ptr); /* uri: host part */
Christopher Faulete010c802018-10-24 10:36:45 +0200307 chunk_memcat(temp, path.ptr, path.len); /* uri: new path */
308 chunk_memcat(temp, p.ptr + plen, p.len - plen); /* uri: QS part */
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100309 uri = ist2(temp->area + meth.len + vsn.len, uri.len - plen + path.len);
Christopher Faulete010c802018-10-24 10:36:45 +0200310
311 /* create the new start line */
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100312 return http_replace_stline(htx, meth, uri, vsn);
Christopher Faulete010c802018-10-24 10:36:45 +0200313}
314
315/* Replace the request query-string in the HTX message <htx> by <query>. The
316 * host part and the path are preserved. It returns 1 on success, otherwise
317 * 0.
318 */
319int http_replace_req_query(struct htx *htx, const struct ist query)
320{
321 struct buffer *temp = get_trash_chunk();
Christopher Faulet297fbb42019-05-13 14:41:27 +0200322 struct htx_sl *sl = http_get_stline(htx);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100323 struct ist meth, uri, vsn, q;
Christopher Faulete010c802018-10-24 10:36:45 +0200324 int offset = 1;
325
Willy Tarreaucdce54c2019-02-12 12:02:27 +0100326 if (!sl)
327 return 0;
328
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100329 uri = htx_sl_req_uri(sl);
330 q = uri;
Christopher Faulete010c802018-10-24 10:36:45 +0200331 while (q.len > 0 && *(q.ptr) != '?') {
332 q.ptr++;
333 q.len--;
334 }
335
336 /* skip the question mark or indicate that we must insert it
337 * (but only if the format string is not empty then).
338 */
339 if (q.len) {
340 q.ptr++;
341 q.len--;
342 }
343 else if (query.len > 1)
344 offset = 0;
345
346 /* Start by copying old method and version and create the new uri */
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100347 chunk_memcat(temp, HTX_SL_REQ_MPTR(sl), HTX_SL_REQ_MLEN(sl)); /* meth */
348 meth = ist2(temp->area, HTX_SL_REQ_MLEN(sl));
Christopher Faulete010c802018-10-24 10:36:45 +0200349
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100350 chunk_memcat(temp, HTX_SL_REQ_VPTR(sl), HTX_SL_REQ_VLEN(sl)); /* vsn */
351 vsn = ist2(temp->area + meth.len, HTX_SL_REQ_VLEN(sl));
Christopher Faulete010c802018-10-24 10:36:45 +0200352
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100353 chunk_memcat(temp, uri.ptr, q.ptr - uri.ptr); /* uri: host + path part */
354 chunk_memcat(temp, query.ptr + offset, query.len - offset); /* uri: new QS */
355 uri = ist2(temp->area + meth.len + vsn.len, uri.len - q.len + query.len - offset);
Christopher Faulete010c802018-10-24 10:36:45 +0200356
357 /* create the new start line */
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100358 return http_replace_stline(htx, meth, uri, vsn);
Christopher Faulete010c802018-10-24 10:36:45 +0200359}
360
361/* Replace the response status in the HTX message <htx> by <status>. It returns
362 * 1 on success, otherwise 0.
363*/
364int http_replace_res_status(struct htx *htx, const struct ist status)
365{
366 struct buffer *temp = get_trash_chunk();
Christopher Faulet297fbb42019-05-13 14:41:27 +0200367 struct htx_sl *sl = http_get_stline(htx);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100368 struct ist vsn, reason;
Christopher Faulete010c802018-10-24 10:36:45 +0200369
Willy Tarreaucdce54c2019-02-12 12:02:27 +0100370 if (!sl)
371 return 0;
372
Christopher Faulete010c802018-10-24 10:36:45 +0200373 /* Start by copying old uri and version */
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100374 chunk_memcat(temp, HTX_SL_RES_VPTR(sl), HTX_SL_RES_VLEN(sl)); /* vsn */
375 vsn = ist2(temp->area, HTX_SL_RES_VLEN(sl));
Christopher Faulete010c802018-10-24 10:36:45 +0200376
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100377 chunk_memcat(temp, HTX_SL_RES_RPTR(sl), HTX_SL_RES_RLEN(sl)); /* reason */
378 reason = ist2(temp->area + vsn.len, HTX_SL_RES_RLEN(sl));
Christopher Faulete010c802018-10-24 10:36:45 +0200379
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100380 /* create the new start line */
381 sl->info.res.status = strl2ui(status.ptr, status.len);
382 return http_replace_stline(htx, vsn, status, reason);
Christopher Faulete010c802018-10-24 10:36:45 +0200383}
384
385/* Replace the response reason in the HTX message <htx> by <reason>. It returns
386 * 1 on success, otherwise 0.
387*/
388int http_replace_res_reason(struct htx *htx, const struct ist reason)
389{
390 struct buffer *temp = get_trash_chunk();
Christopher Faulet297fbb42019-05-13 14:41:27 +0200391 struct htx_sl *sl = http_get_stline(htx);
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100392 struct ist vsn, status;
Christopher Faulete010c802018-10-24 10:36:45 +0200393
Willy Tarreaucdce54c2019-02-12 12:02:27 +0100394 if (!sl)
395 return 0;
396
Christopher Faulete010c802018-10-24 10:36:45 +0200397 /* Start by copying old uri and version */
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100398 chunk_memcat(temp, HTX_SL_RES_VPTR(sl), HTX_SL_RES_VLEN(sl)); /* vsn */
399 vsn = ist2(temp->area, HTX_SL_RES_VLEN(sl));
Christopher Faulete010c802018-10-24 10:36:45 +0200400
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100401 chunk_memcat(temp, HTX_SL_RES_CPTR(sl), HTX_SL_RES_CLEN(sl)); /* code */
402 status = ist2(temp->area + vsn.len, HTX_SL_RES_CLEN(sl));
Christopher Faulete010c802018-10-24 10:36:45 +0200403
Christopher Fauletf1ba18d2018-11-26 21:37:08 +0100404 /* create the new start line */
405 return http_replace_stline(htx, vsn, status, reason);
Christopher Faulete010c802018-10-24 10:36:45 +0200406}
407
Christopher Faulet47596d32018-10-22 09:17:28 +0200408/* Replaces a part of a header value referenced in the context <ctx> by
409 * <data>. It returns 1 on success, otherwise it returns 0. The context is
410 * updated if necessary.
411 */
412int http_replace_header_value(struct htx *htx, struct http_hdr_ctx *ctx, const struct ist data)
413{
414 struct htx_blk *blk = ctx->blk;
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200415 struct htx_sl *sl;
Christopher Faulet47596d32018-10-22 09:17:28 +0200416 char *start;
417 struct ist v;
418 uint32_t len, off;
419
420 if (!blk)
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200421 goto fail;
Christopher Faulet47596d32018-10-22 09:17:28 +0200422
423 v = htx_get_blk_value(htx, blk);
424 start = ctx->value.ptr - ctx->lws_before;
425 len = ctx->lws_before + ctx->value.len + ctx->lws_after;
426 off = start - v.ptr;
427
428 blk = htx_replace_blk_value(htx, blk, ist2(start, len), data);
429 if (!blk)
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200430 goto fail;
Christopher Faulet47596d32018-10-22 09:17:28 +0200431
432 v = htx_get_blk_value(htx, blk);
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200433
434 sl = http_get_stline(htx);
435 if (sl && (sl->flags & HTX_SL_F_HAS_AUTHORITY)) {
436 struct ist n = htx_get_blk_name(htx, blk);
437
438 if (isteq(n, ist("host"))) {
439 if (!http_update_authority(htx, sl, v))
440 goto fail;
441 ctx->blk = NULL;
442 http_find_header(htx, ist("host"), ctx, 1);
443 blk = ctx->blk;
444 v = htx_get_blk_value(htx, blk);
445 }
446 }
447
Christopher Faulet47596d32018-10-22 09:17:28 +0200448 ctx->blk = blk;
449 ctx->value.ptr = v.ptr + off;
450 ctx->value.len = data.len;
451 ctx->lws_before = ctx->lws_after = 0;
452
453 return 1;
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200454 fail:
455 return 0;
Christopher Faulet47596d32018-10-22 09:17:28 +0200456}
457
458/* Fully replaces a header referenced in the context <ctx> by the name <name>
459 * with the value <value>. It returns 1 on success, otherwise it returns 0. The
460 * context is updated if necessary.
461 */
462int http_replace_header(struct htx *htx, struct http_hdr_ctx *ctx,
463 const struct ist name, const struct ist value)
464{
465 struct htx_blk *blk = ctx->blk;
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200466 struct htx_sl *sl;
Christopher Faulet47596d32018-10-22 09:17:28 +0200467
468 if (!blk)
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200469 goto fail;
Christopher Faulet47596d32018-10-22 09:17:28 +0200470
471 blk = htx_replace_header(htx, blk, name, value);
472 if (!blk)
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200473 goto fail;
474
475 sl = http_get_stline(htx);
476 if (sl && (sl->flags & HTX_SL_F_HAS_AUTHORITY) && isteq(name, ist("host"))) {
477 if (!http_update_authority(htx, sl, value))
478 goto fail;
479 ctx->blk = NULL;
480 http_find_header(htx, ist("host"), ctx, 1);
481 blk = ctx->blk;
482 }
Christopher Faulet47596d32018-10-22 09:17:28 +0200483
484 ctx->blk = blk;
485 ctx->value = ist(NULL);
486 ctx->lws_before = ctx->lws_after = 0;
487
488 return 1;
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200489 fail:
490 return 0;
Christopher Faulet47596d32018-10-22 09:17:28 +0200491}
492
493/* Remove one value of a header. This only works on a <ctx> returned by
494 * http_find_header function. The value is removed, as well as surrounding commas
495 * if any. If the removed value was alone, the whole header is removed. The
496 * <ctx> is always updated accordingly, as well as the HTX message <htx>. It
497 * returns 1 on success. Otherwise, it returns 0. The <ctx> is always left in a
498 * form that can be handled by http_find_header() to find next occurrence.
499 */
500int http_remove_header(struct htx *htx, struct http_hdr_ctx *ctx)
501{
502 struct htx_blk *blk = ctx->blk;
503 char *start;
504 struct ist v;
505 uint32_t len;
506
507 if (!blk)
508 return 0;
509
510 start = ctx->value.ptr - ctx->lws_before;
511 len = ctx->lws_before + ctx->value.len + ctx->lws_after;
512
513 v = htx_get_blk_value(htx, blk);
514 if (len == v.len) {
515 blk = htx_remove_blk(htx, blk);
Christopher Faulet192c6a22019-06-11 16:32:24 +0200516 if (blk || htx_is_empty(htx)) {
Christopher Faulet47596d32018-10-22 09:17:28 +0200517 ctx->blk = blk;
518 ctx->value = ist2(NULL, 0);
519 ctx->lws_before = ctx->lws_after = 0;
520 }
521 else {
522 ctx->blk = htx_get_blk(htx, htx->tail);
523 ctx->value = htx_get_blk_value(htx, ctx->blk);
524 ctx->lws_before = ctx->lws_after = 0;
525 }
526 return 1;
527 }
528
529 /* This was not the only value of this header. We have to remove the
530 * part pointed by ctx->value. If it is the last entry of the list, we
531 * remove the last separator.
532 */
533 if (start == v.ptr) {
534 /* It's the first header part but not the only one. So remove
535 * the comma after it. */
536 len++;
537 }
538 else {
539 /* There is at least one header part before the removed one. So
540 * remove the comma between them. */
541 start--;
542 len++;
543 }
544 /* Update the block content and its len */
545 memmove(start, start+len, v.len-len);
Christopher Faulet3e2638e2019-06-18 09:49:16 +0200546 htx_change_blk_value_len(htx, blk, v.len-len);
Christopher Faulet47596d32018-10-22 09:17:28 +0200547
548 /* Finally update the ctx */
549 ctx->value.ptr = start;
550 ctx->value.len = 0;
551 ctx->lws_before = ctx->lws_after = 0;
552
553 return 1;
554}
Christopher Faulet7ff1cea2018-10-24 10:39:35 +0200555
Christopher Fauletd7b7a1c2019-10-08 15:24:52 +0200556/* Updates the authority part of the uri with the value <host>. It happens when
557 * the header host is modified. It returns 0 on failure and 1 on success. It is
558 * the caller responsibility to provide the start-line and to be sure the uri
559 * contains an authority. Thus, if no authority is found in the uri, an error is
560 * returned.
561 */
562static int http_update_authority(struct htx *htx, struct htx_sl *sl, const struct ist host)
563{
564 struct buffer *temp = get_trash_chunk();
565 struct ist meth, vsn, uri, authority;
566
567 uri = htx_sl_req_uri(sl);
568 authority = http_get_authority(uri, 1);
569 if (!authority.len || isteq(host, authority))
570 return 0;
571
572 /* Start by copying old method and version */
573 chunk_memcat(temp, HTX_SL_REQ_MPTR(sl), HTX_SL_REQ_MLEN(sl)); /* meth */
574 meth = ist2(temp->area, HTX_SL_REQ_MLEN(sl));
575
576 chunk_memcat(temp, HTX_SL_REQ_VPTR(sl), HTX_SL_REQ_VLEN(sl)); /* vsn */
577 vsn = ist2(temp->area + meth.len, HTX_SL_REQ_VLEN(sl));
578
579 chunk_memcat(temp, uri.ptr, authority.ptr - uri.ptr);
580 chunk_memcat(temp, host.ptr, host.len);
581 chunk_memcat(temp, authority.ptr + authority.len, uri.ptr + uri.len - (authority.ptr + authority.len));
582 uri = ist2(temp->area + meth.len + vsn.len, host.len + uri.len - authority.len); /* uri */
583
584 return http_replace_stline(htx, meth, uri, vsn);
585
586}
587
588/* Update the header host by extracting the authority of the uri <uri>. flags of
589 * the start-line are also updated accordingly. For orgin-form and asterisk-form
590 * uri, the header host is not changed and the flag HTX_SL_F_HAS_AUTHORITY is
591 * removed from the flags of the start-line. Otherwise, this flag is set and the
592 * authority is used to set the value of the header host. This function returns
593 * 0 on failure and 1 on success.
594*/
595static int http_update_host(struct htx *htx, struct htx_sl *sl, const struct ist uri)
596{
597 struct ist authority;
598 struct http_hdr_ctx ctx;
599
600 if (!uri.len || uri.ptr[0] == '/' || uri.ptr[0] == '*') {
601 // origin-form or a asterisk-form (RFC7320 #5.3.1 and #5.3.4)
602 sl->flags &= ~HTX_SL_F_HAS_AUTHORITY;
603 }
604 else {
605 sl->flags |= HTX_SL_F_HAS_AUTHORITY;
606 if (sl->info.req.meth != HTTP_METH_CONNECT) {
607 // absolute-form (RFC7320 #5.3.2)
608 sl->flags |= HTX_SL_F_HAS_SCHM;
609 if (uri.len > 4 && (uri.ptr[0] | 0x20) == 'h')
610 sl->flags |= ((uri.ptr[4] == ':') ? HTX_SL_F_SCHM_HTTP : HTX_SL_F_SCHM_HTTPS);
611
612 authority = http_get_authority(uri, 1);
613 if (!authority.len)
614 goto fail;
615 }
616 else {
617 // authority-form (RFC7320 #5.3.3)
618 authority = uri;
619 }
620
621 /* Replace header host value */
622 ctx.blk = NULL;
623 while (http_find_header(htx, ist("host"), &ctx, 1)) {
624 if (!http_replace_header_value(htx, &ctx, authority))
625 goto fail;
626 }
627
628 }
629 return 1;
630 fail:
631 return 0;
632}
Christopher Faulet7ff1cea2018-10-24 10:39:35 +0200633
634/* Return in <vptr> and <vlen> the pointer and length of occurrence <occ> of
635 * header whose name is <hname> of length <hlen>. If <ctx> is null, lookup is
636 * performed over the whole headers. Otherwise it must contain a valid header
637 * context, initialised with ctx->blk=NULL for the first lookup in a series. If
638 * <occ> is positive or null, occurrence #occ from the beginning (or last ctx)
639 * is returned. Occ #0 and #1 are equivalent. If <occ> is negative (and no less
640 * than -MAX_HDR_HISTORY), the occurrence is counted from the last one which is
641 * -1. The value fetch stops at commas, so this function is suited for use with
642 * list headers.
643 * The return value is 0 if nothing was found, or non-zero otherwise.
644 */
645unsigned int http_get_htx_hdr(const struct htx *htx, const struct ist hdr,
646 int occ, struct http_hdr_ctx *ctx, char **vptr, size_t *vlen)
647{
648 struct http_hdr_ctx local_ctx;
649 struct ist val_hist[MAX_HDR_HISTORY];
650 unsigned int hist_idx;
651 int found;
652
653 if (!ctx) {
654 local_ctx.blk = NULL;
655 ctx = &local_ctx;
656 }
657
658 if (occ >= 0) {
659 /* search from the beginning */
660 while (http_find_header(htx, hdr, ctx, 0)) {
661 occ--;
662 if (occ <= 0) {
663 *vptr = ctx->value.ptr;
664 *vlen = ctx->value.len;
665 return 1;
666 }
667 }
668 return 0;
669 }
670
671 /* negative occurrence, we scan all the list then walk back */
672 if (-occ > MAX_HDR_HISTORY)
673 return 0;
674
675 found = hist_idx = 0;
676 while (http_find_header(htx, hdr, ctx, 0)) {
677 val_hist[hist_idx] = ctx->value;
678 if (++hist_idx >= MAX_HDR_HISTORY)
679 hist_idx = 0;
680 found++;
681 }
682 if (-occ > found)
683 return 0;
684
685 /* OK now we have the last occurrence in [hist_idx-1], and we need to
686 * find occurrence -occ. 0 <= hist_idx < MAX_HDR_HISTORY, and we have
687 * -10 <= occ <= -1. So we have to check [hist_idx%MAX_HDR_HISTORY+occ]
688 * to remain in the 0..9 range.
689 */
690 hist_idx += occ + MAX_HDR_HISTORY;
691 if (hist_idx >= MAX_HDR_HISTORY)
692 hist_idx -= MAX_HDR_HISTORY;
693 *vptr = val_hist[hist_idx].ptr;
694 *vlen = val_hist[hist_idx].len;
695 return 1;
696}
697
698/* Return in <vptr> and <vlen> the pointer and length of occurrence <occ> of
699 * header whose name is <hname> of length <hlen>. If <ctx> is null, lookup is
700 * performed over the whole headers. Otherwise it must contain a valid header
701 * context, initialised with ctx->blk=NULL for the first lookup in a series. If
702 * <occ> is positive or null, occurrence #occ from the beginning (or last ctx)
703 * is returned. Occ #0 and #1 are equivalent. If <occ> is negative (and no less
704 * than -MAX_HDR_HISTORY), the occurrence is counted from the last one which is
705 * -1. This function differs from http_get_hdr() in that it only returns full
706 * line header values and does not stop at commas.
707 * The return value is 0 if nothing was found, or non-zero otherwise.
708 */
709unsigned int http_get_htx_fhdr(const struct htx *htx, const struct ist hdr,
710 int occ, struct http_hdr_ctx *ctx, char **vptr, size_t *vlen)
711{
712 struct http_hdr_ctx local_ctx;
713 struct ist val_hist[MAX_HDR_HISTORY];
714 unsigned int hist_idx;
715 int found;
716
717 if (!ctx) {
718 local_ctx.blk = NULL;
719 ctx = &local_ctx;
720 }
721
722 if (occ >= 0) {
723 /* search from the beginning */
724 while (http_find_header(htx, hdr, ctx, 1)) {
725 occ--;
726 if (occ <= 0) {
727 *vptr = ctx->value.ptr;
728 *vlen = ctx->value.len;
729 return 1;
730 }
731 }
732 return 0;
733 }
734
735 /* negative occurrence, we scan all the list then walk back */
736 if (-occ > MAX_HDR_HISTORY)
737 return 0;
738
739 found = hist_idx = 0;
740 while (http_find_header(htx, hdr, ctx, 1)) {
741 val_hist[hist_idx] = ctx->value;
742 if (++hist_idx >= MAX_HDR_HISTORY)
743 hist_idx = 0;
744 found++;
745 }
746 if (-occ > found)
747 return 0;
748
749 /* OK now we have the last occurrence in [hist_idx-1], and we need to
750 * find occurrence -occ. 0 <= hist_idx < MAX_HDR_HISTORY, and we have
751 * -10 <= occ <= -1. So we have to check [hist_idx%MAX_HDR_HISTORY+occ]
752 * to remain in the 0..9 range.
753 */
754 hist_idx += occ + MAX_HDR_HISTORY;
755 if (hist_idx >= MAX_HDR_HISTORY)
756 hist_idx -= MAX_HDR_HISTORY;
757 *vptr = val_hist[hist_idx].ptr;
758 *vlen = val_hist[hist_idx].len;
759 return 1;
760}
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100761
Christopher Faulet90cc4812019-07-22 16:49:30 +0200762int http_str_to_htx(struct buffer *buf, struct ist raw)
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100763{
764 struct htx *htx;
765 struct htx_sl *sl;
766 struct h1m h1m;
Christopher Faulete4ab11b2019-06-11 15:05:37 +0200767 struct http_hdr hdrs[global.tune.max_http_hdr];
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100768 union h1_sl h1sl;
769 unsigned int flags = HTX_SL_F_IS_RESP;
770 int ret = 0;
771
Christopher Faulet90cc4812019-07-22 16:49:30 +0200772 b_reset(buf);
773 if (!raw.len) {
774 buf->size = 0;
775 buf->area = malloc(raw.len);
776 return 1;
777 }
778
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100779 buf->size = global.tune.bufsize;
780 buf->area = (char *)malloc(buf->size);
781 if (!buf->area)
782 goto error;
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100783
784 h1m_init_res(&h1m);
785 h1m.flags |= H1_MF_NO_PHDR;
786 ret = h1_headers_to_hdr_list(raw.ptr, raw.ptr + raw.len,
787 hdrs, sizeof(hdrs)/sizeof(hdrs[0]), &h1m, &h1sl);
788 if (ret <= 0)
789 goto error;
790
791 if (unlikely(h1sl.st.v.len != 8))
792 goto error;
793 if ((*(h1sl.st.v.ptr + 5) > '1') ||
794 ((*(h1sl.st.v.ptr + 5) == '1') && (*(h1sl.st.v.ptr + 7) >= '1')))
795 h1m.flags |= H1_MF_VER_11;
796
Christopher Faulet1d5ec092019-06-26 14:23:54 +0200797 if (h1sl.st.status < 200 && (h1sl.st.status == 100 || h1sl.st.status >= 102))
798 goto error;
799
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100800 if (h1m.flags & H1_MF_VER_11)
801 flags |= HTX_SL_F_VER_11;
802 if (h1m.flags & H1_MF_XFER_ENC)
803 flags |= HTX_SL_F_XFER_ENC;
Christopher Faulet0d4ce932019-10-16 09:09:04 +0200804 if (h1m.flags & H1_MF_CLEN) {
805 flags |= (HTX_SL_F_XFER_LEN|HTX_SL_F_CLEN);
806 if (h1m.body_len == 0)
807 flags |= HTX_SL_F_BODYLESS;
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100808 }
Christopher Faulet0d4ce932019-10-16 09:09:04 +0200809 if (h1m.flags & H1_MF_CHNK)
810 goto error; /* Unsupported because there is no body parsing */
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100811
812 htx = htx_from_buf(buf);
813 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, h1sl.st.v, h1sl.st.c, h1sl.st.r);
814 if (!sl || !htx_add_all_headers(htx, hdrs))
815 goto error;
816 sl->info.res.status = h1sl.st.status;
817
Willy Tarreau0a7ef022019-05-28 10:30:11 +0200818 while (raw.len > ret) {
819 int sent = htx_add_data(htx, ist2(raw.ptr + ret, raw.len - ret));
820 if (!sent)
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100821 goto error;
Willy Tarreau0a7ef022019-05-28 10:30:11 +0200822 ret += sent;
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100823 }
Christopher Faulet1d5ec092019-06-26 14:23:54 +0200824
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100825 if (!htx_add_endof(htx, HTX_BLK_EOM))
826 goto error;
Christopher Faulet1d5ec092019-06-26 14:23:54 +0200827
Christopher Faulet90cc4812019-07-22 16:49:30 +0200828 return 1;
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100829
830error:
831 if (buf->size)
832 free(buf->area);
Christopher Faulet90cc4812019-07-22 16:49:30 +0200833 return 0;
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100834}
835
836static int http_htx_init(void)
837{
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100838 struct buffer chk;
839 struct ist raw;
840 int rc;
841 int err_code = 0;
842
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100843 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
844 if (!http_err_msgs[rc]) {
845 ha_alert("Internal error: no message defined for HTTP return code %d", rc);
846 err_code |= ERR_ALERT | ERR_FATAL;
847 continue;
848 }
849
850 raw = ist2(http_err_msgs[rc], strlen(http_err_msgs[rc]));
851 if (!http_str_to_htx(&chk, raw)) {
852 ha_alert("Internal error: Unable to convert message in HTX for HTTP return code %d.\n",
853 http_err_codes[rc]);
854 err_code |= ERR_ALERT | ERR_FATAL;
855 }
Christopher Fauletf7346382019-07-17 22:02:08 +0200856 http_err_chunks[rc] = chk;
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100857 }
858end:
859 return err_code;
860}
861
Christopher Faulet58857752020-01-15 15:19:50 +0100862static void http_htx_deinit(void)
863{
Christopher Faulet35cd81d2020-01-15 11:22:56 +0100864 struct http_errors *http_errs, *http_errsb;
Christopher Faulet58857752020-01-15 15:19:50 +0100865 struct ebpt_node *node, *next;
866 struct http_error *http_err;
867
868 node = ebpt_first(&http_error_messages);
869 while (node) {
870 next = ebpt_next(node);
871 ebpt_delete(node);
872 http_err = container_of(node, typeof(*http_err), node);
873 chunk_destroy(&http_err->msg);
874 free(node->key);
875 free(http_err);
876 node = next;
877 }
Christopher Faulet35cd81d2020-01-15 11:22:56 +0100878
879 list_for_each_entry_safe(http_errs, http_errsb, &http_errors_list, list) {
880 free(http_errs->conf.file);
881 free(http_errs->id);
882 LIST_DEL(&http_errs->list);
883 free(http_errs);
884 }
Christopher Faulet58857752020-01-15 15:19:50 +0100885}
886
Christopher Fauleta7b677c2018-11-29 16:48:49 +0100887REGISTER_CONFIG_POSTPARSER("http_htx", http_htx_init);
Christopher Faulet58857752020-01-15 15:19:50 +0100888REGISTER_POST_DEINIT(http_htx_deinit);
Christopher Faulet29f72842019-12-11 15:52:32 +0100889
Christopher Faulet58857752020-01-15 15:19:50 +0100890/* Reads content of the error file <file> and convert it into an HTX message. On
891 * success, the HTX message is returned. On error, NULL is returned and an error
892 * message is written into the <errmsg> buffer.
Christopher Faulet5031ef52020-01-15 11:22:07 +0100893 */
Christopher Faulet58857752020-01-15 15:19:50 +0100894struct buffer *http_load_errorfile(const char *file, char **errmsg)
Christopher Faulet5031ef52020-01-15 11:22:07 +0100895{
Christopher Faulet58857752020-01-15 15:19:50 +0100896 struct buffer *buf = NULL;
897 struct buffer chk;
898 struct ebpt_node *node;
899 struct http_error *http_err;
Christopher Faulet5031ef52020-01-15 11:22:07 +0100900 struct stat stat;
901 char *err = NULL;
902 int errnum, errlen;
903 int fd = -1;
Christopher Faulet58857752020-01-15 15:19:50 +0100904
905 /* already loaded */
906 node = ebis_lookup_len(&http_error_messages, file, strlen(file));
907 if (node) {
908 http_err = container_of(node, typeof(*http_err), node);
909 buf = &http_err->msg;
910 goto out;
911 }
Christopher Faulet5031ef52020-01-15 11:22:07 +0100912
Christopher Faulet58857752020-01-15 15:19:50 +0100913 /* Read the error file content */
Christopher Faulet5031ef52020-01-15 11:22:07 +0100914 fd = open(file, O_RDONLY);
915 if ((fd < 0) || (fstat(fd, &stat) < 0)) {
916 memprintf(errmsg, "error opening file '%s'.", file);
917 goto out;
918 }
919
920 if (stat.st_size <= global.tune.bufsize)
921 errlen = stat.st_size;
922 else {
923 ha_warning("custom error message file '%s' larger than %d bytes. Truncating.\n",
924 file, global.tune.bufsize);
925 errlen = global.tune.bufsize;
926 }
927
928 err = malloc(errlen);
929 if (!err) {
930 memprintf(errmsg, "out of memory.");
931 goto out;
932 }
933
934 errnum = read(fd, err, errlen);
935 if (errnum != errlen) {
936 memprintf(errmsg, "error reading file '%s'.", file);
937 goto out;
938 }
939
Christopher Faulet58857752020-01-15 15:19:50 +0100940 /* Create the node corresponding to the error file */
941 http_err = calloc(1, sizeof(*http_err));
942 if (!http_err) {
943 memprintf(errmsg, "out of memory.");
944 goto out;
945 }
946 http_err->node.key = strdup(file);
947 if (!http_err->node.key) {
948 memprintf(errmsg, "out of memory.");
Christopher Faulet7cde96c2020-01-21 10:10:11 +0100949 free(http_err);
Christopher Faulet58857752020-01-15 15:19:50 +0100950 goto out;
951 }
952
953 /* Convert the error file into an HTX message */
954 if (!http_str_to_htx(&chk, ist2(err, errlen))) {
Christopher Faulet5031ef52020-01-15 11:22:07 +0100955 memprintf(errmsg, "unable to convert custom error message file '%s' in HTX.", file);
Christopher Faulet58857752020-01-15 15:19:50 +0100956 free(http_err->node.key);
957 free(http_err);
Christopher Faulet5031ef52020-01-15 11:22:07 +0100958 goto out;
959 }
960
Christopher Faulet58857752020-01-15 15:19:50 +0100961 /* Insert the node in the tree and return the HTX message */
962 http_err->msg = chk;
963 ebis_insert(&http_error_messages, &http_err->node);
964 buf = &http_err->msg;
965
Christopher Faulet5031ef52020-01-15 11:22:07 +0100966 out:
967 if (fd >= 0)
968 close(fd);
969 free(err);
Christopher Faulet58857752020-01-15 15:19:50 +0100970 return buf;
Christopher Faulet5031ef52020-01-15 11:22:07 +0100971}
972
Christopher Faulet58857752020-01-15 15:19:50 +0100973/* Convert the raw http message <msg> into an HTX message. On sucess, the HTX
974 * message is returned. On error, NULL is returned and an error message is
975 * written into the <errmsg> buffer.
Christopher Fauletbdf65262020-01-16 15:51:59 +0100976 */
Christopher Faulet58857752020-01-15 15:19:50 +0100977struct buffer *http_load_errormsg(const char *key, const struct ist msg, char **errmsg)
Christopher Fauletbdf65262020-01-16 15:51:59 +0100978{
Christopher Faulet58857752020-01-15 15:19:50 +0100979 struct buffer *buf = NULL;
980 struct buffer chk;
981 struct ebpt_node *node;
982 struct http_error *http_err;
983
984 /* already loaded */
985 node = ebis_lookup_len(&http_error_messages, key, strlen(key));
986 if (node) {
987 http_err = container_of(node, typeof(*http_err), node);
988 buf = &http_err->msg;
989 goto out;
990 }
991 /* Create the node corresponding to the error file */
992 http_err = calloc(1, sizeof(*http_err));
993 if (!http_err) {
994 memprintf(errmsg, "out of memory.");
995 goto out;
996 }
997 http_err->node.key = strdup(key);
998 if (!http_err->node.key) {
999 memprintf(errmsg, "out of memory.");
Christopher Faulet7cde96c2020-01-21 10:10:11 +01001000 free(http_err);
Christopher Faulet58857752020-01-15 15:19:50 +01001001 goto out;
1002 }
Christopher Fauletbdf65262020-01-16 15:51:59 +01001003
1004 /* Convert the error file into an HTX message */
Christopher Faulet58857752020-01-15 15:19:50 +01001005 if (!http_str_to_htx(&chk, msg)) {
Christopher Fauletbdf65262020-01-16 15:51:59 +01001006 memprintf(errmsg, "unable to convert message in HTX.");
Christopher Faulet58857752020-01-15 15:19:50 +01001007 free(http_err->node.key);
1008 free(http_err);
Christopher Fauletbdf65262020-01-16 15:51:59 +01001009 goto out;
1010 }
Christopher Fauletbdf65262020-01-16 15:51:59 +01001011
Christopher Faulet58857752020-01-15 15:19:50 +01001012 /* Insert the node in the tree and return the HTX message */
1013 http_err->msg = chk;
1014 ebis_insert(&http_error_messages, &http_err->node);
1015 buf = &http_err->msg;
Christopher Fauletbdf65262020-01-16 15:51:59 +01001016 out:
Christopher Faulet58857752020-01-15 15:19:50 +01001017 return buf;
Christopher Fauletbdf65262020-01-16 15:51:59 +01001018}
1019
Christopher Faulet5031ef52020-01-15 11:22:07 +01001020/* This function parses the raw HTTP error file <file> for the status code
Christopher Faulet58857752020-01-15 15:19:50 +01001021 * <status>. It returns NULL if there is any error, otherwise it return the
1022 * corresponding HTX message.
Christopher Faulet5031ef52020-01-15 11:22:07 +01001023 */
Christopher Faulet58857752020-01-15 15:19:50 +01001024struct buffer *http_parse_errorfile(int status, const char *file, char **errmsg)
Christopher Faulet5031ef52020-01-15 11:22:07 +01001025{
Christopher Faulet58857752020-01-15 15:19:50 +01001026 struct buffer *buf = NULL;
1027 int rc;
Christopher Faulet5031ef52020-01-15 11:22:07 +01001028
1029 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
1030 if (http_err_codes[rc] == status) {
Christopher Faulet58857752020-01-15 15:19:50 +01001031 buf = http_load_errorfile(file, errmsg);
Christopher Faulet5031ef52020-01-15 11:22:07 +01001032 break;
1033 }
1034 }
1035
1036 if (rc >= HTTP_ERR_SIZE)
1037 memprintf(errmsg, "status code '%d' not handled.", status);
Christopher Faulet58857752020-01-15 15:19:50 +01001038 return buf;
Christopher Fauletbdf65262020-01-16 15:51:59 +01001039}
1040
1041/* This function creates HTX error message corresponding to a redirect message
1042 * for the status code <status>. <url> is used as location url for the
Christopher Faulet58857752020-01-15 15:19:50 +01001043 * redirect. <errloc> is used to know if it is a 302 or a 303 redirect. It
1044 * returns NULL if there is any error, otherwise it return the corresponding HTX
1045 * message.
Christopher Fauletbdf65262020-01-16 15:51:59 +01001046 */
Christopher Faulet58857752020-01-15 15:19:50 +01001047struct buffer *http_parse_errorloc(int errloc, int status, const char *url, char **errmsg)
Christopher Fauletbdf65262020-01-16 15:51:59 +01001048{
Christopher Faulet58857752020-01-15 15:19:50 +01001049 struct buffer *buf = NULL;
Christopher Fauletbdf65262020-01-16 15:51:59 +01001050 const char *msg;
Christopher Faulet58857752020-01-15 15:19:50 +01001051 char *key = NULL, *err = NULL;
Christopher Fauletbdf65262020-01-16 15:51:59 +01001052 int rc, errlen;
Christopher Fauletbdf65262020-01-16 15:51:59 +01001053
1054 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
1055 if (http_err_codes[rc] == status) {
Christopher Faulet58857752020-01-15 15:19:50 +01001056 /* Create the error key */
1057 if (!memprintf(&key, "errorloc%d %s", errloc, url)) {
1058 memprintf(errmsg, "out of memory.");
1059 goto out;
1060 }
Christopher Fauletbdf65262020-01-16 15:51:59 +01001061 /* Create the error message */
1062 msg = (errloc == 302 ? HTTP_302 : HTTP_303);
1063 errlen = strlen(msg) + strlen(url) + 5;
1064 err = malloc(errlen);
1065 if (!err) {
1066 memprintf(errmsg, "out of memory.");
1067 goto out;
1068 }
1069 errlen = snprintf(err, errlen, "%s%s\r\n\r\n", msg, url);
1070
1071 /* Load it */
Christopher Faulet58857752020-01-15 15:19:50 +01001072 buf = http_load_errormsg(key, ist2(err, errlen), errmsg);
Christopher Fauletbdf65262020-01-16 15:51:59 +01001073 break;
1074 }
1075 }
1076
1077 if (rc >= HTTP_ERR_SIZE)
1078 memprintf(errmsg, "status code '%d' not handled.", status);
1079out:
Christopher Faulet58857752020-01-15 15:19:50 +01001080 free(key);
Christopher Fauletbdf65262020-01-16 15:51:59 +01001081 free(err);
Christopher Faulet58857752020-01-15 15:19:50 +01001082 return buf;
Christopher Faulet5031ef52020-01-15 11:22:07 +01001083}
1084
Christopher Faulet07f41f72020-01-16 16:16:06 +01001085/* Parses the "errorloc[302|303]" proxy keyword */
1086static int proxy_parse_errorloc(char **args, int section, struct proxy *curpx,
1087 struct proxy *defpx, const char *file, int line,
1088 char **errmsg)
1089{
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001090 struct conf_errors *conf_err;
Christopher Faulet07f41f72020-01-16 16:16:06 +01001091 struct buffer *msg;
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001092 int errloc, status;
1093 int ret = 0;
Christopher Faulet07f41f72020-01-16 16:16:06 +01001094
1095 if (warnifnotcap(curpx, PR_CAP_FE | PR_CAP_BE, file, line, args[0], NULL)) {
1096 ret = 1;
1097 goto out;
1098 }
1099
1100 if (*(args[1]) == 0 || *(args[2]) == 0) {
1101 memprintf(errmsg, "%s : expects <status_code> and <url> as arguments.\n", args[0]);
1102 ret = -1;
1103 goto out;
1104 }
1105
1106 status = atol(args[1]);
1107 errloc = (!strcmp(args[0], "errorloc303") ? 303 : 302);
1108 msg = http_parse_errorloc(errloc, status, args[2], errmsg);
1109 if (!msg) {
1110 memprintf(errmsg, "%s : %s", args[0], *errmsg);
1111 ret = -1;
1112 goto out;
1113 }
1114
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001115 conf_err = calloc(1, sizeof(*conf_err));
1116 if (!conf_err) {
1117 memprintf(errmsg, "%s : out of memory.", args[0]);
1118 ret = -1;
1119 goto out;
1120 }
1121 conf_err->type = 1;
1122 conf_err->info.errorfile.status = status;
1123 conf_err->info.errorfile.msg = msg;
1124 conf_err->file = strdup(file);
1125 conf_err->line = line;
1126 LIST_ADDQ(&curpx->conf.errors, &conf_err->list);
Christopher Faulet07f41f72020-01-16 16:16:06 +01001127
1128 out:
1129 return ret;
Christopher Faulet07f41f72020-01-16 16:16:06 +01001130
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001131}
Christopher Faulet07f41f72020-01-16 16:16:06 +01001132
1133/* Parses the "errorfile" proxy keyword */
1134static int proxy_parse_errorfile(char **args, int section, struct proxy *curpx,
1135 struct proxy *defpx, const char *file, int line,
1136 char **errmsg)
1137{
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001138 struct conf_errors *conf_err;
Christopher Faulet07f41f72020-01-16 16:16:06 +01001139 struct buffer *msg;
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001140 int status;
1141 int ret = 0;
Christopher Faulet07f41f72020-01-16 16:16:06 +01001142
1143 if (warnifnotcap(curpx, PR_CAP_FE | PR_CAP_BE, file, line, args[0], NULL)) {
1144 ret = 1;
1145 goto out;
1146 }
1147
1148 if (*(args[1]) == 0 || *(args[2]) == 0) {
1149 memprintf(errmsg, "%s : expects <status_code> and <file> as arguments.\n", args[0]);
1150 ret = -1;
1151 goto out;
1152 }
1153
1154 status = atol(args[1]);
1155 msg = http_parse_errorfile(status, args[2], errmsg);
1156 if (!msg) {
1157 memprintf(errmsg, "%s : %s", args[0], *errmsg);
1158 ret = -1;
1159 goto out;
1160 }
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001161
1162 conf_err = calloc(1, sizeof(*conf_err));
1163 if (!conf_err) {
1164 memprintf(errmsg, "%s : out of memory.", args[0]);
1165 ret = -1;
1166 goto out;
1167 }
1168 conf_err->type = 1;
1169 conf_err->info.errorfile.status = status;
1170 conf_err->info.errorfile.msg = msg;
1171 conf_err->file = strdup(file);
1172 conf_err->line = line;
1173 LIST_ADDQ(&curpx->conf.errors, &conf_err->list);
1174
1175 out:
1176 return ret;
1177
1178}
1179
1180/* Parses the "errorfiles" proxy keyword */
1181static int proxy_parse_errorfiles(char **args, int section, struct proxy *curpx,
1182 struct proxy *defpx, const char *file, int line,
1183 char **err)
1184{
1185 struct conf_errors *conf_err = NULL;
1186 char *name = NULL;
1187 int rc, ret = 0;
1188
1189 if (warnifnotcap(curpx, PR_CAP_FE | PR_CAP_BE, file, line, args[0], NULL)) {
1190 ret = 1;
1191 goto out;
1192 }
1193
1194 if (!*(args[1])) {
1195 memprintf(err, "%s : expects <name> as argument.", args[0]);
1196 ret = -1;
1197 goto out;
1198 }
1199
1200 name = strdup(args[1]);
1201 conf_err = calloc(1, sizeof(*conf_err));
1202 if (!name || !conf_err) {
1203 memprintf(err, "%s : out of memory.", args[0]);
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001204 goto error;
1205 }
1206 conf_err->type = 0;
1207
1208 conf_err->info.errorfiles.name = name;
1209 if (!*(args[2])) {
1210 for (rc = 0; rc < HTTP_ERR_SIZE; rc++)
1211 conf_err->info.errorfiles.status[rc] = 1;
1212 }
1213 else {
1214 int cur_arg, status;
1215 for (cur_arg = 2; *(args[cur_arg]); cur_arg++) {
1216 status = atol(args[cur_arg]);
1217
1218 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
1219 if (http_err_codes[rc] == status) {
1220 conf_err->info.errorfiles.status[rc] = 2;
1221 break;
1222 }
1223 }
1224 if (rc >= HTTP_ERR_SIZE) {
1225 memprintf(err, "%s : status code '%d' not handled.", args[0], status);
Christopher Faulet7cde96c2020-01-21 10:10:11 +01001226 goto error;
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001227 }
1228 }
1229 }
1230 conf_err->file = strdup(file);
1231 conf_err->line = line;
1232 LIST_ADDQ(&curpx->conf.errors, &conf_err->list);
1233 out:
1234 return ret;
1235
1236 error:
1237 free(name);
1238 free(conf_err);
Christopher Faulet7cde96c2020-01-21 10:10:11 +01001239 ret = -1;
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001240 goto out;
1241}
1242
1243/* Check "errorfiles" proxy keyword */
1244static int proxy_check_errors(struct proxy *px)
1245{
1246 struct conf_errors *conf_err, *conf_err_back;
1247 struct http_errors *http_errs;
1248 int rc, err = 0;
1249
1250 list_for_each_entry_safe(conf_err, conf_err_back, &px->conf.errors, list) {
1251 if (conf_err->type == 1) {
1252 /* errorfile */
1253 rc = http_get_status_idx(conf_err->info.errorfile.status);
1254 px->errmsg[rc] = conf_err->info.errorfile.msg;
1255 }
1256 else {
1257 /* errorfiles */
1258 list_for_each_entry(http_errs, &http_errors_list, list) {
1259 if (strcmp(http_errs->id, conf_err->info.errorfiles.name) == 0)
1260 break;
1261 }
Christopher Faulet07f41f72020-01-16 16:16:06 +01001262
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001263 /* unknown http-errors section */
1264 if (&http_errs->list == &http_errors_list) {
1265 ha_alert("config : proxy '%s': unknown http-errors section '%s' (at %s:%d).\n",
1266 px->id, conf_err->info.errorfiles.name, conf_err->file, conf_err->line);
1267 err |= ERR_ALERT | ERR_FATAL;
1268 free(conf_err->info.errorfiles.name);
1269 goto next;
1270 }
1271
1272 free(conf_err->info.errorfiles.name);
1273 for (rc = 0; rc < HTTP_ERR_SIZE; rc++) {
1274 if (conf_err->info.errorfiles.status[rc] > 0) {
1275 if (http_errs->errmsg[rc])
1276 px->errmsg[rc] = http_errs->errmsg[rc];
1277 else if (conf_err->info.errorfiles.status[rc] == 2)
1278 ha_warning("config: proxy '%s' : status '%d' not declared in"
1279 " http-errors section '%s' (at %s:%d).\n",
1280 px->id, http_err_codes[rc], http_errs->id,
1281 conf_err->file, conf_err->line);
1282 }
1283 }
1284 }
1285 next:
1286 LIST_DEL(&conf_err->list);
1287 free(conf_err->file);
1288 free(conf_err);
1289 }
Christopher Faulet07f41f72020-01-16 16:16:06 +01001290
1291 out:
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001292 return err;
1293}
1294
Christopher Faulet0a589fd2020-01-22 14:47:04 +01001295static int post_check_errors()
1296{
1297 struct ebpt_node *node;
1298 struct http_error *http_err;
1299 struct htx *htx;
1300 int err_code = 0;
1301
1302 node = ebpt_first(&http_error_messages);
1303 while (node) {
1304 http_err = container_of(node, typeof(*http_err), node);
1305 if (b_is_null(&http_err->msg))
1306 goto next;
1307 htx = htxbuf(&http_err->msg);
1308 if (htx_free_data_space(htx) < global.tune.maxrewrite) {
1309 ha_warning("config: errorfile '%s' runs over the buffer space"
1310 " reserved to headers rewritting. It may lead to internal errors if "
1311 " http-final-response rules are evaluated on this message.\n",
1312 (char *)node->key);
1313 err_code |= ERR_WARN;
1314 }
1315 next:
1316 node = ebpt_next(node);
1317 }
1318
1319 return err_code;
1320}
1321
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001322int proxy_dup_default_conf_errors(struct proxy *curpx, struct proxy *defpx, char **errmsg)
1323{
1324 struct conf_errors *conf_err, *new_conf_err = NULL;
1325 int ret = 0;
1326
1327 list_for_each_entry(conf_err, &defpx->conf.errors, list) {
1328 new_conf_err = calloc(1, sizeof(*new_conf_err));
1329 if (!new_conf_err) {
1330 memprintf(errmsg, "unable to duplicate default errors (out of memory).");
1331 goto out;
1332 }
1333 new_conf_err->type = conf_err->type;
1334 if (conf_err->type == 1) {
1335 new_conf_err->info.errorfile.status = conf_err->info.errorfile.status;
1336 new_conf_err->info.errorfile.msg = conf_err->info.errorfile.msg;
1337 }
1338 else {
1339 new_conf_err->info.errorfiles.name = strdup(conf_err->info.errorfiles.name);
1340 if (!new_conf_err->info.errorfiles.name) {
1341 memprintf(errmsg, "unable to duplicate default errors (out of memory).");
1342 goto out;
1343 }
1344 memcpy(&new_conf_err->info.errorfiles.status, &conf_err->info.errorfiles.status,
1345 sizeof(conf_err->info.errorfiles.status));
1346 }
1347 new_conf_err->file = strdup(conf_err->file);
1348 new_conf_err->line = conf_err->line;
1349 LIST_ADDQ(&curpx->conf.errors, &new_conf_err->list);
1350 new_conf_err = NULL;
1351 }
1352 ret = 1;
1353
1354 out:
1355 free(new_conf_err);
Christopher Faulet07f41f72020-01-16 16:16:06 +01001356 return ret;
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001357}
1358
1359void proxy_release_conf_errors(struct proxy *px)
1360{
1361 struct conf_errors *conf_err, *conf_err_back;
Christopher Faulet07f41f72020-01-16 16:16:06 +01001362
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001363 list_for_each_entry_safe(conf_err, conf_err_back, &px->conf.errors, list) {
1364 if (conf_err->type == 0)
1365 free(conf_err->info.errorfiles.name);
1366 LIST_DEL(&conf_err->list);
1367 free(conf_err->file);
1368 free(conf_err);
1369 }
Christopher Faulet35cd81d2020-01-15 11:22:56 +01001370}
1371
1372/*
1373 * Parse an <http-errors> section.
1374 * Returns the error code, 0 if OK, or any combination of :
1375 * - ERR_ABORT: must abort ASAP
1376 * - ERR_FATAL: we can continue parsing but not start the service
1377 * - ERR_WARN: a warning has been emitted
1378 * - ERR_ALERT: an alert has been emitted
1379 * Only the two first ones can stop processing, the two others are just
1380 * indicators.
1381 */
1382static int cfg_parse_http_errors(const char *file, int linenum, char **args, int kwm)
1383{
1384 static struct http_errors *curr_errs = NULL;
1385 int err_code = 0;
1386 const char *err;
1387 char *errmsg = NULL;
1388
1389 if (strcmp(args[0], "http-errors") == 0) { /* new errors section */
1390 if (!*args[1]) {
1391 ha_alert("parsing [%s:%d] : missing name for http-errors section.\n", file, linenum);
1392 err_code |= ERR_ALERT | ERR_ABORT;
1393 goto out;
1394 }
1395
1396 err = invalid_char(args[1]);
1397 if (err) {
1398 ha_alert("parsing [%s:%d] : character '%c' is not permitted in '%s' name '%s'.\n",
1399 file, linenum, *err, args[0], args[1]);
1400 err_code |= ERR_ALERT | ERR_FATAL;
1401 }
1402
1403 list_for_each_entry(curr_errs, &http_errors_list, list) {
1404 /* Error if two errors section owns the same name */
1405 if (strcmp(curr_errs->id, args[1]) == 0) {
1406 ha_alert("parsing [%s:%d]: http-errors section '%s' already exists (declared at %s:%d).\n",
1407 file, linenum, args[1], curr_errs->conf.file, curr_errs->conf.line);
1408 err_code |= ERR_ALERT | ERR_FATAL;
1409 }
1410 }
1411
1412 if ((curr_errs = calloc(1, sizeof(*curr_errs))) == NULL) {
1413 ha_alert("parsing [%s:%d] : out of memory.\n", file, linenum);
1414 err_code |= ERR_ALERT | ERR_ABORT;
1415 goto out;
1416 }
1417
1418 LIST_ADDQ(&http_errors_list, &curr_errs->list);
1419 curr_errs->id = strdup(args[1]);
1420 curr_errs->conf.file = strdup(file);
1421 curr_errs->conf.line = linenum;
1422 }
1423 else if (!strcmp(args[0], "errorfile")) { /* error message from a file */
1424 struct buffer *msg;
1425 int status, rc;
1426
1427 if (*(args[1]) == 0 || *(args[2]) == 0) {
1428 ha_alert("parsing [%s:%d] : %s: expects <status_code> and <file> as arguments.\n",
1429 file, linenum, args[0]);
1430 err_code |= ERR_ALERT | ERR_FATAL;
1431 goto out;
1432 }
1433
1434 status = atol(args[1]);
1435 msg = http_parse_errorfile(status, args[2], &errmsg);
1436 if (!msg) {
1437 ha_alert("parsing [%s:%d] : %s : %s\n", file, linenum, args[0], errmsg);
1438 err_code |= ERR_ALERT | ERR_FATAL;
1439 goto out;
1440 }
1441 rc = http_get_status_idx(status);
1442 curr_errs->errmsg[rc] = msg;
1443 }
1444 else if (*args[0] != 0) {
1445 ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection);
1446 err_code |= ERR_ALERT | ERR_FATAL;
1447 goto out;
1448 }
1449
1450out:
1451 free(errmsg);
1452 return err_code;
Christopher Faulet07f41f72020-01-16 16:16:06 +01001453}
1454
1455static struct cfg_kw_list cfg_kws = {ILH, {
1456 { CFG_LISTEN, "errorloc", proxy_parse_errorloc },
1457 { CFG_LISTEN, "errorloc302", proxy_parse_errorloc },
1458 { CFG_LISTEN, "errorloc303", proxy_parse_errorloc },
1459 { CFG_LISTEN, "errorfile", proxy_parse_errorfile },
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001460 { CFG_LISTEN, "errorfiles", proxy_parse_errorfiles },
Christopher Faulet07f41f72020-01-16 16:16:06 +01001461 { 0, NULL, NULL },
1462}};
1463
1464INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
Christopher Faulet76edc0f2020-01-13 15:52:01 +01001465REGISTER_POST_PROXY_CHECK(proxy_check_errors);
Christopher Faulet0a589fd2020-01-22 14:47:04 +01001466REGISTER_POST_CHECK(post_check_errors);
Christopher Faulet07f41f72020-01-16 16:16:06 +01001467
Christopher Faulet35cd81d2020-01-15 11:22:56 +01001468REGISTER_CONFIG_SECTION("http-errors", cfg_parse_http_errors, NULL);
1469
Christopher Faulet29f72842019-12-11 15:52:32 +01001470/************************************************************************/
1471/* HTX sample fetches */
1472/************************************************************************/
1473
1474/* Returns 1 if a stream is an HTX stream. Otherwise, it returns 0. */
1475static int
1476smp_fetch_is_htx(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
1477{
1478 if (!smp->strm)
1479 return 0;
1480
1481 smp->data.u.sint = !!IS_HTX_STRM(smp->strm);
1482 smp->data.type = SMP_T_BOOL;
1483 return 1;
1484}
1485
1486/* Returns the number of blocks in an HTX message. The channel is chosen
1487 * depending on the sample direction. */
1488static int
1489smp_fetch_htx_nbblks(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
1490{
1491 struct channel *chn;
1492 struct htx *htx;
1493
1494 if (!smp->strm)
1495 return 0;
1496
1497 chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
1498 htx = smp_prefetch_htx(smp, chn, 0);
1499 if (!htx)
1500 return 0;
1501
1502 smp->data.u.sint = htx_nbblks(htx);
1503 smp->data.type = SMP_T_SINT;
1504 smp->flags = SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
1505 return 1;
1506}
1507
1508/* Returns the size of an HTX message. The channel is chosen depending on the
1509 * sample direction. */
1510static int
1511smp_fetch_htx_size(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
1512{
1513 struct channel *chn;
1514 struct htx *htx;
1515
1516 if (!smp->strm)
1517 return 0;
1518
1519 chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
1520 htx = smp_prefetch_htx(smp, chn, 0);
1521 if (!htx)
1522 return 0;
1523
1524 smp->data.u.sint = htx->size;
1525 smp->data.type = SMP_T_SINT;
1526 smp->flags = SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
1527 return 1;
1528}
1529
1530/* Returns the data size of an HTX message. The channel is chosen depending on the
1531 * sample direction. */
1532static int
1533smp_fetch_htx_data(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
1534{
1535 struct channel *chn;
1536 struct htx *htx;
1537
1538 if (!smp->strm)
1539 return 0;
1540
1541 chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
1542 htx = smp_prefetch_htx(smp, chn, 0);
1543 if (!htx)
1544 return 0;
1545
1546 smp->data.u.sint = htx->data;
1547 smp->data.type = SMP_T_SINT;
1548 smp->flags = SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
1549 return 1;
1550}
1551
1552/* Returns the used space (data+meta) of an HTX message. The channel is chosen
1553 * depending on the sample direction. */
1554static int
1555smp_fetch_htx_used(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
1556{
1557 struct channel *chn;
1558 struct htx *htx;
1559
1560 if (!smp->strm)
1561 return 0;
1562
1563 chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
1564 htx = smp_prefetch_htx(smp, chn, 0);
1565 if (!htx)
1566 return 0;
1567
1568 smp->data.u.sint = htx_used_space(htx);
1569 smp->data.type = SMP_T_SINT;
1570 smp->flags = SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
1571 return 1;
1572}
1573
1574/* Returns the free space (size-used) of an HTX message. The channel is chosen
1575 * depending on the sample direction. */
1576static int
1577smp_fetch_htx_free(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
1578{
1579 struct channel *chn;
1580 struct htx *htx;
1581
1582 if (!smp->strm)
1583 return 0;
1584
1585 chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
1586 htx = smp_prefetch_htx(smp, chn, 0);
1587 if (!htx)
1588 return 0;
1589
1590 smp->data.u.sint = htx_free_space(htx);
1591 smp->data.type = SMP_T_SINT;
1592 smp->flags = SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
1593 return 1;
1594}
1595
1596/* Returns the free space for data (free-sizeof(blk)) of an HTX message. The
1597 * channel is chosen depending on the sample direction. */
1598static int
1599smp_fetch_htx_free_data(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
1600{
1601 struct channel *chn;
1602 struct htx *htx;
1603
1604 if (!smp->strm)
1605 return 0;
1606
1607 chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
1608 htx = smp_prefetch_htx(smp, chn, 0);
1609 if (!htx)
1610 return 0;
1611
1612 smp->data.u.sint = htx_free_data_space(htx);
1613 smp->data.type = SMP_T_SINT;
1614 smp->flags = SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
1615 return 1;
1616}
1617
1618/* Returns 1 if the HTX message contains an EOM block. Otherwise it returns
1619 * 0. Concretely, it only checks the tail. The channel is chosen depending on
1620 * the sample direction. */
1621static int
1622smp_fetch_htx_has_eom(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
1623{
1624 struct channel *chn;
1625 struct htx *htx;
1626
1627 if (!smp->strm)
1628 return 0;
1629
1630 chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
1631 htx = smp_prefetch_htx(smp, chn, 0);
1632 if (!htx)
1633 return 0;
1634
1635 smp->data.u.sint = (htx_get_tail_type(htx) == HTX_BLK_EOM);
1636 smp->data.type = SMP_T_BOOL;
1637 smp->flags = SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
1638 return 1;
1639}
1640
1641/* Returns the type of a specific HTX block, if found in the message. Otherwise
1642 * HTX_BLK_UNUSED is returned. Any positive integer (>= 0) is supported or
1643 * "head", "tail" or "first". The channel is chosen depending on the sample
1644 * direction. */
1645static int
1646smp_fetch_htx_blk_type(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
1647{
1648 struct channel *chn;
1649 struct htx *htx;
1650 enum htx_blk_type type;
1651 int32_t pos;
1652
1653 if (!smp->strm || !arg_p)
1654 return 0;
1655
1656 chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
1657 htx = smp_prefetch_htx(smp, chn, 0);
1658 if (!htx)
1659 return 0;
1660
1661 pos = arg_p[0].data.sint;
1662 if (pos == -1)
1663 type = htx_get_head_type(htx);
1664 else if (pos == -2)
1665 type = htx_get_tail_type(htx);
1666 else if (pos == -3)
1667 type = htx_get_first_type(htx);
1668 else
1669 type = ((pos >= htx->head && pos <= htx->tail)
1670 ? htx_get_blk_type(htx_get_blk(htx, pos))
1671 : HTX_BLK_UNUSED);
1672
1673 chunk_initstr(&smp->data.u.str, htx_blk_type_str(type));
1674 smp->data.type = SMP_T_STR;
1675 smp->flags = SMP_F_CONST | SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
1676 return 1;
1677}
1678
1679/* Returns the size of a specific HTX block, if found in the message. Otherwise
1680 * 0 is returned. Any positive integer (>= 0) is supported or "head", "tail" or
1681 * "first". The channel is chosen depending on the sample direction. */
1682static int
1683smp_fetch_htx_blk_size(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
1684{
1685 struct channel *chn;
1686 struct htx *htx;
1687 struct htx_blk *blk;
1688 int32_t pos;
1689
1690 if (!smp->strm || !arg_p)
1691 return 0;
1692
1693 chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
1694 htx = smp_prefetch_htx(smp, chn, 0);
1695 if (!htx)
1696 return 0;
1697
1698 pos = arg_p[0].data.sint;
1699 if (pos == -1)
1700 blk = htx_get_head_blk(htx);
1701 else if (pos == -2)
1702 blk = htx_get_tail_blk(htx);
1703 else if (pos == -3)
1704 blk = htx_get_first_blk(htx);
1705 else
1706 blk = ((pos >= htx->head && pos <= htx->tail) ? htx_get_blk(htx, pos) : NULL);
1707
1708 smp->data.u.sint = (blk ? htx_get_blksz(blk) : 0);
1709 smp->data.type = SMP_T_SINT;
1710 smp->flags = SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
1711 return 1;
1712}
1713
1714/* Returns the start-line if the selected HTX block exists and is a
1715 * start-line. Otherwise 0 an empty string. Any positive integer (>= 0) is
1716 * supported or "head", "tail" or "first". The channel is chosen depending on
1717 * the sample direction. */
1718static int
1719smp_fetch_htx_blk_stline(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
1720{
1721 struct buffer *temp;
1722 struct channel *chn;
1723 struct htx *htx;
1724 struct htx_blk *blk;
1725 struct htx_sl *sl;
1726 int32_t pos;
1727
1728 if (!smp->strm || !arg_p)
1729 return 0;
1730
1731 chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
1732 htx = smp_prefetch_htx(smp, chn, 0);
1733 if (!htx)
1734 return 0;
1735
1736 pos = arg_p[0].data.sint;
1737 if (pos == -1)
1738 blk = htx_get_head_blk(htx);
1739 else if (pos == -2)
1740 blk = htx_get_tail_blk(htx);
1741 else if (pos == -3)
1742 blk = htx_get_first_blk(htx);
1743 else
1744 blk = ((pos >= htx->head && pos <= htx->tail) ? htx_get_blk(htx, pos) : NULL);
1745
1746 if (!blk || (htx_get_blk_type(blk) != HTX_BLK_REQ_SL && htx_get_blk_type(blk) != HTX_BLK_RES_SL)) {
1747 smp->data.u.str.size = 0;
1748 smp->data.u.str.area = "";
1749 smp->data.u.str.data = 0;
1750 }
1751 else {
1752 sl = htx_get_blk_ptr(htx, blk);
1753
1754 temp = get_trash_chunk();
1755 chunk_istcat(temp, htx_sl_p1(sl));
1756 temp->area[temp->data++] = ' ';
1757 chunk_istcat(temp, htx_sl_p2(sl));
1758 temp->area[temp->data++] = ' ';
1759 chunk_istcat(temp, htx_sl_p3(sl));
1760
1761 smp->data.u.str = *temp;
1762 }
1763
1764 smp->data.type = SMP_T_STR;
1765 smp->flags = SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
1766 return 1;
1767}
1768
1769/* Returns the header name if the selected HTX block exists and is a header or a
1770 * trailer. Otherwise 0 an empty string. Any positive integer (>= 0) is
1771 * supported or "head", "tail" or "first". The channel is chosen depending on
1772 * the sample direction. */
1773static int
1774smp_fetch_htx_blk_hdrname(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
1775{
1776 struct channel *chn;
1777 struct htx *htx;
1778 struct htx_blk *blk;
1779 int32_t pos;
1780
1781 if (!smp->strm || !arg_p)
1782 return 0;
1783
1784 chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
1785 htx = smp_prefetch_htx(smp, chn, 0);
1786 if (!htx)
1787 return 0;
1788
1789 pos = arg_p[0].data.sint;
1790 if (pos == -1)
1791 blk = htx_get_head_blk(htx);
1792 else if (pos == -2)
1793 blk = htx_get_tail_blk(htx);
1794 else if (pos == -3)
1795 blk = htx_get_first_blk(htx);
1796 else
1797 blk = ((pos >= htx->head && pos <= htx->tail) ? htx_get_blk(htx, pos) : NULL);
1798
1799 if (!blk || (htx_get_blk_type(blk) != HTX_BLK_HDR && htx_get_blk_type(blk) != HTX_BLK_TLR)) {
1800 smp->data.u.str.size = 0;
1801 smp->data.u.str.area = "";
1802 smp->data.u.str.data = 0;
1803 }
1804 else {
1805 struct ist name = htx_get_blk_name(htx, blk);
1806
1807 chunk_initlen(&smp->data.u.str, name.ptr, name.len, name.len);
1808 }
1809 smp->data.type = SMP_T_STR;
1810 smp->flags = SMP_F_CONST | SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
1811 return 1;
1812}
1813
1814/* Returns the header value if the selected HTX block exists and is a header or
1815 * a trailer. Otherwise 0 an empty string. Any positive integer (>= 0) is
1816 * supported or "head", "tail" or "first". The channel is chosen depending on
1817 * the sample direction. */
1818static int
1819smp_fetch_htx_blk_hdrval(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
1820{
1821 struct channel *chn;
1822 struct htx *htx;
1823 struct htx_blk *blk;
1824 int32_t pos;
1825
1826 if (!smp->strm || !arg_p)
1827 return 0;
1828
1829 chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
1830 htx = smp_prefetch_htx(smp, chn, 0);
1831 if (!htx)
1832 return 0;
1833
1834 pos = arg_p[0].data.sint;
1835 if (pos == -1)
1836 blk = htx_get_head_blk(htx);
1837 else if (pos == -2)
1838 blk = htx_get_tail_blk(htx);
1839 else if (pos == -3)
1840 blk = htx_get_first_blk(htx);
1841 else
1842 blk = ((pos >= htx->head && pos <= htx->tail) ? htx_get_blk(htx, pos) : NULL);
1843
1844 if (!blk || (htx_get_blk_type(blk) != HTX_BLK_HDR && htx_get_blk_type(blk) != HTX_BLK_TLR)) {
1845 smp->data.u.str.size = 0;
1846 smp->data.u.str.area = "";
1847 smp->data.u.str.data = 0;
1848 }
1849 else {
1850 struct ist val = htx_get_blk_value(htx, blk);
1851
1852 chunk_initlen(&smp->data.u.str, val.ptr, val.len, val.len);
1853 }
1854 smp->data.type = SMP_T_STR;
1855 smp->flags = SMP_F_CONST | SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
1856 return 1;
1857}
1858
1859/* Returns the value if the selected HTX block exists and is a data
1860 * block. Otherwise 0 an empty string. Any positive integer (>= 0) is supported
1861 * or "head", "tail" or "first". The channel is chosen depending on the sample
1862 * direction. */
1863static int
Christopher Fauletc5db14c2020-01-08 14:51:03 +01001864smp_fetch_htx_blk_data(const struct arg *arg_p, struct sample *smp, const char *kw, void *private)
Christopher Faulet29f72842019-12-11 15:52:32 +01001865{
1866 struct channel *chn;
1867 struct htx *htx;
1868 struct htx_blk *blk;
1869 int32_t pos;
1870
1871 if (!smp->strm || !arg_p)
1872 return 0;
1873
1874 chn = ((smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_RES) ? &smp->strm->res : &smp->strm->req;
1875 htx = smp_prefetch_htx(smp, chn, 0);
1876 if (!htx)
1877 return 0;
1878
1879 pos = arg_p[0].data.sint;
1880 if (pos == -1)
1881 blk = htx_get_head_blk(htx);
1882 else if (pos == -2)
1883 blk = htx_get_tail_blk(htx);
1884 else if (pos == -3)
1885 blk = htx_get_first_blk(htx);
1886 else
1887 blk = ((pos >= htx->head && pos <= htx->tail) ? htx_get_blk(htx, pos) : NULL);
1888
1889 if (!blk || htx_get_blk_type(blk) != HTX_BLK_DATA) {
1890 smp->data.u.str.size = 0;
1891 smp->data.u.str.area = "";
1892 smp->data.u.str.data = 0;
1893 }
1894 else {
1895 struct ist val = htx_get_blk_value(htx, blk);
1896
1897 chunk_initlen(&smp->data.u.str, val.ptr, val.len, val.len);
1898 }
Christopher Faulet8178e402020-01-08 14:38:58 +01001899 smp->data.type = SMP_T_BIN;
Christopher Faulet29f72842019-12-11 15:52:32 +01001900 smp->flags = SMP_F_CONST | SMP_F_VOLATILE | SMP_F_MAY_CHANGE;
1901 return 1;
1902}
1903
1904/* This function is used to validate the arguments passed to any "htx_blk" fetch
1905 * keywords. An argument is expected by these keywords. It must be a positive
1906 * integer or on of the following strings: "head", "tail" or "first". It returns
1907 * 0 on error, and a non-zero value if OK.
1908 */
1909int val_blk_arg(struct arg *arg, char **err_msg)
1910{
1911 if (arg[0].type != ARGT_STR || !arg[0].data.str.data) {
1912 memprintf(err_msg, "a block position is expected (> 0) or a special block name (head, tail, first)");
1913 return 0;
1914 }
1915 if (arg[0].data.str.data == 4 && !strncmp(arg[0].data.str.area, "head", 4)) {
1916 free(arg[0].data.str.area);
1917 arg[0].type = ARGT_SINT;
1918 arg[0].data.sint = -1;
1919 }
1920 else if (arg[0].data.str.data == 4 && !strncmp(arg[0].data.str.area, "tail", 4)) {
1921 free(arg[0].data.str.area);
1922 arg[0].type = ARGT_SINT;
1923 arg[0].data.sint = -2;
1924 }
1925 else if (arg[0].data.str.data == 5 && !strncmp(arg[0].data.str.area, "first", 5)) {
1926 free(arg[0].data.str.area);
1927 arg[0].type = ARGT_SINT;
1928 arg[0].data.sint = -3;
1929 }
1930 else {
1931 int pos;
1932
1933 for (pos = 0; pos < arg[0].data.str.data; pos++) {
1934 if (!isdigit(arg[0].data.str.area[pos])) {
1935 memprintf(err_msg, "invalid block position");
1936 return 0;
1937 }
1938 }
1939
1940 pos = strl2uic(arg[0].data.str.area, arg[0].data.str.data);
1941 if (pos < 0) {
1942 memprintf(err_msg, "block position must not be negative");
1943 return 0;
1944 }
1945 free(arg[0].data.str.area);
1946 arg[0].type = ARGT_SINT;
1947 arg[0].data.sint = pos;
1948 }
1949
1950 return 1;
1951}
1952
1953
1954/* Note: must not be declared <const> as its list will be overwritten.
1955 * Note: htx sample fetches should only used for developpement purpose.
1956 */
1957static struct sample_fetch_kw_list sample_fetch_keywords = {ILH, {
Christopher Faulet01f44452020-01-08 14:23:40 +01001958 { "internal.strm.is_htx", smp_fetch_is_htx, 0, NULL, SMP_T_BOOL, SMP_USE_L6REQ },
Christopher Faulet29f72842019-12-11 15:52:32 +01001959
Christopher Faulet01f44452020-01-08 14:23:40 +01001960 { "internal.htx.nbblks", smp_fetch_htx_nbblks, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV|SMP_USE_HRSHV},
1961 { "internal.htx.size", smp_fetch_htx_size, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV|SMP_USE_HRSHV},
1962 { "internal.htx.data", smp_fetch_htx_data, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV|SMP_USE_HRSHV},
1963 { "internal.htx.used", smp_fetch_htx_used, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV|SMP_USE_HRSHV},
1964 { "internal.htx.free", smp_fetch_htx_free, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV|SMP_USE_HRSHV},
1965 { "internal.htx.free_data", smp_fetch_htx_free_data, 0, NULL, SMP_T_SINT, SMP_USE_HRQHV|SMP_USE_HRSHV},
1966 { "internal.htx.has_eom", smp_fetch_htx_has_eom, 0, NULL, SMP_T_BOOL, SMP_USE_HRQHV|SMP_USE_HRSHV},
Christopher Faulet29f72842019-12-11 15:52:32 +01001967
Christopher Faulet01f44452020-01-08 14:23:40 +01001968 { "internal.htx_blk.type", smp_fetch_htx_blk_type, ARG1(1,STR), val_blk_arg, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV},
1969 { "internal.htx_blk.size", smp_fetch_htx_blk_size, ARG1(1,STR), val_blk_arg, SMP_T_SINT, SMP_USE_HRQHV|SMP_USE_HRSHV},
1970 { "internal.htx_blk.start_line", smp_fetch_htx_blk_stline, ARG1(1,STR), val_blk_arg, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV},
1971 { "internal.htx_blk.hdrname", smp_fetch_htx_blk_hdrname, ARG1(1,STR), val_blk_arg, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV},
1972 { "internal.htx_blk.hdrval", smp_fetch_htx_blk_hdrval, ARG1(1,STR), val_blk_arg, SMP_T_STR, SMP_USE_HRQHV|SMP_USE_HRSHV},
Christopher Fauletc5db14c2020-01-08 14:51:03 +01001973 { "internal.htx_blk.data", smp_fetch_htx_blk_data, ARG1(1,STR), val_blk_arg, SMP_T_BIN, SMP_USE_HRQHV|SMP_USE_HRSHV},
Christopher Faulet29f72842019-12-11 15:52:32 +01001974
1975 { /* END */ },
1976}};
1977
1978INITCALL1(STG_REGISTER, sample_register_fetches, &sample_fetch_keywords);