blob: b31ff934c7f5ec5c1970ef033b8277389afb3ca3 [file] [log] [blame]
Willy Tarreauf24ea8e2017-11-21 19:55:27 +01001/*
2 * HTTP/2 protocol processing
3 *
4 * Copyright 2017 Willy Tarreau <w@1wt.eu>
5 * Copyright (C) 2017 HAProxy Technologies
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining
8 * a copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sublicense, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be
16 * included in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 */
27
Willy Tarreaua1bd1fa2019-03-29 17:26:33 +010028#include <inttypes.h>
Willy Tarreau4c7e4b72020-05-27 12:58:42 +020029#include <haproxy/api.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020030#include <haproxy/global.h>
Willy Tarreaubf073142020-06-03 12:04:01 +020031#include <haproxy/h2.h>
Willy Tarreau0017be02020-06-02 19:25:28 +020032#include <haproxy/http-hdr-t.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020033#include <haproxy/http.h>
Amaury Denoyelle03534102021-07-07 10:49:28 +020034#include <haproxy/http_htx.h>
Willy Tarreau16f958c2020-06-03 08:44:35 +020035#include <haproxy/htx.h>
Willy Tarreaueb6f7012020-05-27 16:21:26 +020036#include <import/ist.h>
Willy Tarreaub2551052020-06-09 09:07:15 +020037
Willy Tarreauf24ea8e2017-11-21 19:55:27 +010038
Willy Tarreau9c84d822019-01-30 15:09:21 +010039struct h2_frame_definition h2_frame_definition[H2_FT_ENTRIES] = {
40 [H2_FT_DATA ] = { .dir = 3, .min_id = 1, .max_id = H2_MAX_STREAM_ID, .min_len = 0, .max_len = H2_MAX_FRAME_LEN, },
41 [H2_FT_HEADERS ] = { .dir = 3, .min_id = 1, .max_id = H2_MAX_STREAM_ID, .min_len = 1, .max_len = H2_MAX_FRAME_LEN, },
42 [H2_FT_PRIORITY ] = { .dir = 3, .min_id = 1, .max_id = H2_MAX_STREAM_ID, .min_len = 5, .max_len = 5, },
43 [H2_FT_RST_STREAM ] = { .dir = 3, .min_id = 1, .max_id = H2_MAX_STREAM_ID, .min_len = 4, .max_len = 4, },
44 [H2_FT_SETTINGS ] = { .dir = 3, .min_id = 0, .max_id = 0, .min_len = 0, .max_len = H2_MAX_FRAME_LEN, },
45 [H2_FT_PUSH_PROMISE ] = { .dir = 0, .min_id = 1, .max_id = H2_MAX_STREAM_ID, .min_len = 4, .max_len = H2_MAX_FRAME_LEN, },
46 [H2_FT_PING ] = { .dir = 3, .min_id = 0, .max_id = 0, .min_len = 8, .max_len = 8, },
47 [H2_FT_GOAWAY ] = { .dir = 3, .min_id = 0, .max_id = 0, .min_len = 8, .max_len = H2_MAX_FRAME_LEN, },
48 [H2_FT_WINDOW_UPDATE] = { .dir = 3, .min_id = 0, .max_id = H2_MAX_STREAM_ID, .min_len = 4, .max_len = 4, },
49 [H2_FT_CONTINUATION ] = { .dir = 3, .min_id = 1, .max_id = H2_MAX_STREAM_ID, .min_len = 0, .max_len = H2_MAX_FRAME_LEN, },
50};
Willy Tarreauf24ea8e2017-11-21 19:55:27 +010051
Willy Tarreau54f53ef2019-11-22 16:02:43 +010052/* Looks into <ist> for forbidden characters for header values (0x00, 0x0A,
53 * 0x0D), starting at pointer <start> which must be within <ist>. Returns
54 * non-zero if such a character is found, 0 otherwise. When run on unlikely
55 * header match, it's recommended to first check for the presence of control
56 * chars using ist_find_ctl().
57 */
58static int has_forbidden_char(const struct ist ist, const char *start)
59{
60 do {
61 if ((uint8_t)*start <= 0x0d &&
62 (1U << (uint8_t)*start) & ((1<<13) | (1<<10) | (1<<0)))
63 return 1;
64 start++;
65 } while (start < ist.ptr + ist.len);
66 return 0;
67}
68
Willy Tarreaubeefaee2018-12-19 13:08:08 +010069/* Parse the Content-Length header field of an HTTP/2 request. The function
70 * checks all possible occurrences of a comma-delimited value, and verifies
71 * if any of them doesn't match a previous value. It returns <0 if a value
72 * differs, 0 if the whole header can be dropped (i.e. already known), or >0
73 * if the value can be indexed (first one). In the last case, the value might
74 * be adjusted and the caller must only add the updated value.
75 */
76int h2_parse_cont_len_header(unsigned int *msgf, struct ist *value, unsigned long long *body_len)
77{
78 char *e, *n;
79 unsigned long long cl;
80 int not_first = !!(*msgf & H2_MSGF_BODY_CL);
81 struct ist word;
82
83 word.ptr = value->ptr - 1; // -1 for next loop's pre-increment
84 e = value->ptr + value->len;
85
86 while (++word.ptr < e) {
Ilya Shipitsin6fb0f212020-04-02 15:25:26 +050087 /* skip leading delimiter and blanks */
Willy Tarreaubeefaee2018-12-19 13:08:08 +010088 if (unlikely(HTTP_IS_LWS(*word.ptr)))
89 continue;
90
91 /* digits only now */
92 for (cl = 0, n = word.ptr; n < e; n++) {
93 unsigned int c = *n - '0';
94 if (unlikely(c > 9)) {
95 /* non-digit */
96 if (unlikely(n == word.ptr)) // spaces only
97 goto fail;
98 break;
99 }
100 if (unlikely(cl > ULLONG_MAX / 10ULL))
101 goto fail; /* multiply overflow */
102 cl = cl * 10ULL;
103 if (unlikely(cl + c < cl))
104 goto fail; /* addition overflow */
105 cl = cl + c;
106 }
107
108 /* keep a copy of the exact cleaned value */
109 word.len = n - word.ptr;
110
111 /* skip trailing LWS till next comma or EOL */
112 for (; n < e; n++) {
113 if (!HTTP_IS_LWS(*n)) {
114 if (unlikely(*n != ','))
115 goto fail;
116 break;
117 }
118 }
119
120 /* if duplicate, must be equal */
121 if (*msgf & H2_MSGF_BODY_CL && cl != *body_len)
122 goto fail;
123
124 /* OK, store this result as the one to be indexed */
125 *msgf |= H2_MSGF_BODY_CL;
126 *body_len = cl;
127 *value = word;
128 word.ptr = n;
129 }
130 /* here we've reached the end with a single value or a series of
131 * identical values, all matching previous series if any. The last
132 * parsed value was sent back into <value>. We just have to decide
133 * if this occurrence has to be indexed (it's the first one) or
134 * silently skipped (it's not the first one)
135 */
136 return !not_first;
137 fail:
138 return -1;
139}
140
Willy Tarreau6deb4122018-11-27 15:34:18 +0100141/* Prepare the request line into <htx> from pseudo headers stored in <phdr[]>.
142 * <fields> indicates what was found so far. This should be called once at the
143 * detection of the first general header field or at the end of the request if
144 * no general header field was found yet. Returns the created start line on
145 * success, or NULL on failure. Upon success, <msgf> is updated with a few
146 * H2_MSGF_* flags indicating what was found while parsing.
Willy Tarreau2be362c2019-10-08 11:59:37 +0200147 *
148 * The rules below deserve a bit of explanation. There tends to be some
149 * confusion regarding H2's authority vs the Host header. They are different
150 * though may sometimes be exchanged. In H2, the request line is broken into :
151 * - :method
152 * - :scheme
153 * - :authority
154 * - :path
155 *
156 * An equivalent HTTP/1.x absolute-form request would then look like :
157 * <:method> <:scheme>://<:authority><:path> HTTP/x.y
158 *
159 * Except for CONNECT which doesn't have scheme nor path and looks like :
160 * <:method> <:authority> HTTP/x.y
161 *
162 * It's worth noting that H2 still supports an encoding to map H1 origin-form
163 * and asterisk-form requests. These ones do not specify the authority. However
164 * in H2 they must still specify the scheme, which is not present in H1. Also,
165 * when encoding an absolute-form H1 request without a path, the path
166 * automatically becomes "/" except for the OPTIONS method where it
167 * becomes "*".
168 *
169 * As such it is explicitly permitted for an H2 client to send a request
170 * featuring a Host header and no :authority, though it's not the recommended
171 * way to use H2 for a client. It is however the only permitted way to encode
172 * an origin-form H1 request over H2. Thus we need to respect such differences
173 * as much as possible when re-encoding the H2 request into HTX.
Willy Tarreau6deb4122018-11-27 15:34:18 +0100174 */
175static struct htx_sl *h2_prepare_htx_reqline(uint32_t fields, struct ist *phdr, struct htx *htx, unsigned int *msgf)
176{
Amaury Denoyellec9a0afc2020-12-11 17:53:09 +0100177 struct ist uri, meth_sl;
Willy Tarreau6deb4122018-11-27 15:34:18 +0100178 unsigned int flags = HTX_SL_F_NONE;
179 struct htx_sl *sl;
Willy Tarreau9255e7e2019-03-05 10:47:37 +0100180 size_t i;
Willy Tarreau6deb4122018-11-27 15:34:18 +0100181
182 if ((fields & H2_PHDR_FND_METH) && isteq(phdr[H2_PHDR_IDX_METH], ist("CONNECT"))) {
Amaury Denoyellec9a0afc2020-12-11 17:53:09 +0100183 if (fields & H2_PHDR_FND_PROT) {
184 /* rfc 8441 Extended Connect Protocol
185 * #4 :scheme and :path must be present, as well as
186 * :authority like all h2 requests
187 */
188 if (!(fields & H2_PHDR_FND_SCHM)) {
189 /* missing scheme */
190 goto fail;
191 }
192 else if (!(fields & H2_PHDR_FND_PATH)) {
193 /* missing path */
194 goto fail;
195 }
196 else if (!(fields & H2_PHDR_FND_AUTH)) {
197 /* missing authority */
198 goto fail;
199 }
200
201 flags |= HTX_SL_F_HAS_SCHM;
202 if (isteqi(phdr[H2_PHDR_IDX_SCHM], ist("http")))
203 flags |= HTX_SL_F_SCHM_HTTP;
204 else if (isteqi(phdr[H2_PHDR_IDX_SCHM], ist("https")))
205 flags |= HTX_SL_F_SCHM_HTTPS;
Willy Tarreau9e0c2b52021-08-10 15:37:34 +0200206 else if (!http_validate_scheme(phdr[H2_PHDR_IDX_SCHM]))
207 htx->flags |= HTX_FL_PARSING_ERROR;
Amaury Denoyellec9a0afc2020-12-11 17:53:09 +0100208
209 meth_sl = ist("GET");
210
211 *msgf |= H2_MSGF_EXT_CONNECT;
212 /* no ES on the HEADERS frame but no body either for
213 * Extended CONNECT */
214 *msgf &= ~H2_MSGF_BODY;
Willy Tarreau6deb4122018-11-27 15:34:18 +0100215 }
Amaury Denoyellec9a0afc2020-12-11 17:53:09 +0100216 else {
217 /* RFC 7540 #8.2.6 regarding CONNECT: ":scheme" and ":path"
218 * MUST be omitted ; ":authority" contains the host and port
219 * to connect to.
220 */
221 if (fields & H2_PHDR_FND_SCHM) {
222 /* scheme not allowed */
223 goto fail;
224 }
225 else if (fields & H2_PHDR_FND_PATH) {
226 /* path not allowed */
227 goto fail;
228 }
229 else if (!(fields & H2_PHDR_FND_AUTH)) {
230 /* missing authority */
231 goto fail;
232 }
233
234 meth_sl = phdr[H2_PHDR_IDX_METH];
Willy Tarreau6deb4122018-11-27 15:34:18 +0100235 }
Amaury Denoyellec9a0afc2020-12-11 17:53:09 +0100236
Willy Tarreau6deb4122018-11-27 15:34:18 +0100237 *msgf |= H2_MSGF_BODY_TUNNEL;
238 }
239 else if ((fields & (H2_PHDR_FND_METH|H2_PHDR_FND_SCHM|H2_PHDR_FND_PATH)) !=
240 (H2_PHDR_FND_METH|H2_PHDR_FND_SCHM|H2_PHDR_FND_PATH)) {
241 /* RFC 7540 #8.1.2.3 : all requests MUST include exactly one
242 * valid value for the ":method", ":scheme" and ":path" phdr
243 * unless it is a CONNECT request.
244 */
245 if (!(fields & H2_PHDR_FND_METH)) {
246 /* missing method */
247 goto fail;
248 }
249 else if (!(fields & H2_PHDR_FND_SCHM)) {
250 /* missing scheme */
251 goto fail;
252 }
253 else {
254 /* missing path */
255 goto fail;
256 }
257 }
Willy Tarreau2be362c2019-10-08 11:59:37 +0200258 else { /* regular methods */
Willy Tarreau92919f72019-10-08 16:53:07 +0200259 /* RFC3986#6.2.2.1: scheme is case-insensitive. We need to
260 * classify the scheme as "present/http", "present/https",
261 * "present/other", "absent" so as to decide whether or not
262 * we're facing a normalized URI that will have to be encoded
263 * in origin or absolute form. Indeed, 7540#8.1.2.3 says that
264 * clients should use the absolute form, thus we cannot infer
265 * whether or not the client wanted to use a proxy here.
266 */
267 flags |= HTX_SL_F_HAS_SCHM;
268 if (isteqi(phdr[H2_PHDR_IDX_SCHM], ist("http")))
269 flags |= HTX_SL_F_SCHM_HTTP;
270 else if (isteqi(phdr[H2_PHDR_IDX_SCHM], ist("https")))
271 flags |= HTX_SL_F_SCHM_HTTPS;
Willy Tarreau9e0c2b52021-08-10 15:37:34 +0200272 else if (!http_validate_scheme(phdr[H2_PHDR_IDX_SCHM]))
273 htx->flags |= HTX_FL_PARSING_ERROR;
Amaury Denoyellec9a0afc2020-12-11 17:53:09 +0100274
275 meth_sl = phdr[H2_PHDR_IDX_METH];
Willy Tarreau92919f72019-10-08 16:53:07 +0200276 }
277
Willy Tarreau6c6b9a52021-08-10 16:30:55 +0200278 if (fields & H2_PHDR_FND_PATH) {
279 /* 7540#8.1.2.3: :path must not be empty, and must be either
280 * '*' or an RFC3986 "path-absolute" starting with a "/" but
281 * not with "//".
282 */
283 if (unlikely(!phdr[H2_PHDR_IDX_PATH].len))
284 goto fail;
285 else if (unlikely(phdr[H2_PHDR_IDX_PATH].ptr[0] != '/')) {
286 if (!isteq(phdr[H2_PHDR_IDX_PATH], ist("*")))
287 goto fail;
288 }
289 else if (phdr[H2_PHDR_IDX_PATH].len > 1 &&
290 phdr[H2_PHDR_IDX_PATH].ptr[1] == '/')
291 goto fail;
292 }
293
Willy Tarreau92919f72019-10-08 16:53:07 +0200294 if (!(flags & HTX_SL_F_HAS_SCHM)) {
295 /* no scheme, use authority only (CONNECT) */
296 uri = phdr[H2_PHDR_IDX_AUTH];
Willy Tarreau1440fe82019-10-08 17:34:50 +0200297 flags |= HTX_SL_F_HAS_AUTHORITY;
Willy Tarreau92919f72019-10-08 16:53:07 +0200298 }
Willy Tarreau30ee1ef2019-10-08 18:33:19 +0200299 else if (fields & H2_PHDR_FND_AUTH) {
300 /* authority is present, let's use the absolute form. We simply
301 * use the trash to concatenate them since all of them MUST fit
302 * in a bufsize since it's where they come from.
Willy Tarreau92919f72019-10-08 16:53:07 +0200303 */
304 uri = ist2bin(trash.area, phdr[H2_PHDR_IDX_SCHM]);
305 istcat(&uri, ist("://"), trash.size);
306 istcat(&uri, phdr[H2_PHDR_IDX_AUTH], trash.size);
307 if (!isteq(phdr[H2_PHDR_IDX_PATH], ist("*")))
308 istcat(&uri, phdr[H2_PHDR_IDX_PATH], trash.size);
Willy Tarreau1440fe82019-10-08 17:34:50 +0200309 flags |= HTX_SL_F_HAS_AUTHORITY;
Willy Tarreau30ee1ef2019-10-08 18:33:19 +0200310
311 if (flags & (HTX_SL_F_SCHM_HTTP|HTX_SL_F_SCHM_HTTPS)) {
312 /* we don't know if it was originally an absolute or a
313 * relative request because newer versions of HTTP use
314 * the absolute URI format by default, which we call
315 * the normalized URI format internally. This is the
316 * strongly recommended way of sending a request for
317 * a regular client, so we cannot distinguish this
318 * from a request intended for a proxy. For other
319 * schemes however there is no doubt.
320 */
321 flags |= HTX_SL_F_NORMALIZED_URI;
322 }
Willy Tarreau92919f72019-10-08 16:53:07 +0200323 }
324 else {
325 /* usual schemes with or without authority, use origin form */
326 uri = phdr[H2_PHDR_IDX_PATH];
Willy Tarreau1440fe82019-10-08 17:34:50 +0200327 if (fields & H2_PHDR_FND_AUTH)
328 flags |= HTX_SL_F_HAS_AUTHORITY;
Willy Tarreau2be362c2019-10-08 11:59:37 +0200329 }
Willy Tarreau6deb4122018-11-27 15:34:18 +0100330
Willy Tarreau2be362c2019-10-08 11:59:37 +0200331 /* make sure the final URI isn't empty. Note that 7540#8.1.2.3 states
332 * that :path must not be empty.
333 */
Willy Tarreau92919f72019-10-08 16:53:07 +0200334 if (!uri.len)
Willy Tarreau6deb4122018-11-27 15:34:18 +0100335 goto fail;
336
Willy Tarreau2be362c2019-10-08 11:59:37 +0200337 /* The final URI must not contain LWS nor CTL characters */
Willy Tarreau92919f72019-10-08 16:53:07 +0200338 for (i = 0; i < uri.len; i++) {
339 unsigned char c = uri.ptr[i];
Willy Tarreau9255e7e2019-03-05 10:47:37 +0100340 if (HTTP_IS_LWS(c) || HTTP_IS_CTL(c))
341 htx->flags |= HTX_FL_PARSING_ERROR;
342 }
343
Willy Tarreau6deb4122018-11-27 15:34:18 +0100344 /* Set HTX start-line flags */
345 flags |= HTX_SL_F_VER_11; // V2 in fact
346 flags |= HTX_SL_F_XFER_LEN; // xfer len always known with H2
347
Amaury Denoyellec9a0afc2020-12-11 17:53:09 +0100348 sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, meth_sl, uri, ist("HTTP/2.0"));
Willy Tarreau6deb4122018-11-27 15:34:18 +0100349 if (!sl)
350 goto fail;
351
Amaury Denoyellec9a0afc2020-12-11 17:53:09 +0100352 sl->info.req.meth = find_http_meth(meth_sl.ptr, meth_sl.len);
Christopher Faulet7d247f02020-12-02 14:26:36 +0100353 if (sl->info.req.meth == HTTP_METH_HEAD)
354 *msgf |= H2_MSGF_BODYLESS_RSP;
Willy Tarreau6deb4122018-11-27 15:34:18 +0100355 return sl;
356 fail:
357 return NULL;
358}
359
360/* Takes an H2 request present in the headers list <list> terminated by a name
361 * being <NULL,0> and emits the equivalent HTX request according to the rules
362 * documented in RFC7540 #8.1.2. The output contents are emitted in <htx>, and
363 * non-zero is returned if some bytes were emitted. In case of error, a
364 * negative error code is returned.
365 *
366 * Upon success, <msgf> is filled with a few H2_MSGF_* flags indicating what
367 * was found while parsing. The caller must set it to zero in or H2_MSGF_BODY
368 * if a body is detected (!ES).
369 *
370 * The headers list <list> must be composed of :
371 * - n.name != NULL, n.len > 0 : literal header name
372 * - n.name == NULL, n.len > 0 : indexed pseudo header name number <n.len>
373 * among H2_PHDR_IDX_*
374 * - n.name ignored, n.len == 0 : end of list
375 * - in all cases except the end of list, v.name and v.len must designate a
376 * valid value.
377 *
378 * The Cookie header will be reassembled at the end, and for this, the <list>
379 * will be used to create a linked list, so its contents may be destroyed.
380 */
Willy Tarreau4790f7c2019-01-24 11:33:02 +0100381int h2_make_htx_request(struct http_hdr *list, struct htx *htx, unsigned int *msgf, unsigned long long *body_len)
Willy Tarreau6deb4122018-11-27 15:34:18 +0100382{
383 struct ist phdr_val[H2_PHDR_NUM_ENTRIES];
384 uint32_t fields; /* bit mask of H2_PHDR_FND_* */
385 uint32_t idx;
386 int ck, lck; /* cookie index and last cookie index */
387 int phdr;
388 int ret;
389 int i;
390 struct htx_sl *sl = NULL;
391 unsigned int sl_flags = 0;
Willy Tarreau54f53ef2019-11-22 16:02:43 +0100392 const char *ctl;
Willy Tarreau6deb4122018-11-27 15:34:18 +0100393
394 lck = ck = -1; // no cookie for now
395 fields = 0;
396 for (idx = 0; list[idx].n.len != 0; idx++) {
397 if (!list[idx].n.ptr) {
398 /* this is an indexed pseudo-header */
399 phdr = list[idx].n.len;
400 }
401 else {
402 /* this can be any type of header */
Willy Tarreau146f53a2019-11-24 10:34:39 +0100403 /* RFC7540#8.1.2: upper case not allowed in header field names.
404 * #10.3: header names must be valid (i.e. match a token).
405 * For pseudo-headers we check from 2nd char and for other ones
406 * from the first char, because HTTP_IS_TOKEN() also excludes
407 * the colon.
408 */
Willy Tarreau6deb4122018-11-27 15:34:18 +0100409 phdr = h2_str_to_phdr(list[idx].n);
Willy Tarreau146f53a2019-11-24 10:34:39 +0100410
411 for (i = !!phdr; i < list[idx].n.len; i++)
412 if ((uint8_t)(list[idx].n.ptr[i] - 'A') < 'Z' - 'A' || !HTTP_IS_TOKEN(list[idx].n.ptr[i]))
413 goto fail;
Willy Tarreau6deb4122018-11-27 15:34:18 +0100414 }
415
Willy Tarreau54f53ef2019-11-22 16:02:43 +0100416 /* RFC7540#10.3: intermediaries forwarding to HTTP/1 must take care of
417 * rejecting NUL, CR and LF characters.
418 */
419 ctl = ist_find_ctl(list[idx].v);
420 if (unlikely(ctl) && has_forbidden_char(list[idx].v, ctl))
421 goto fail;
422
Willy Tarreau6deb4122018-11-27 15:34:18 +0100423 if (phdr > 0 && phdr < H2_PHDR_NUM_ENTRIES) {
424 /* insert a pseudo header by its index (in phdr) and value (in value) */
425 if (fields & ((1 << phdr) | H2_PHDR_FND_NONE)) {
426 if (fields & H2_PHDR_FND_NONE) {
427 /* pseudo header field after regular headers */
428 goto fail;
429 }
430 else {
431 /* repeated pseudo header field */
432 goto fail;
433 }
434 }
435 fields |= 1 << phdr;
436 phdr_val[phdr] = list[idx].v;
437 continue;
438 }
439 else if (phdr != 0) {
440 /* invalid pseudo header -- should never happen here */
441 goto fail;
442 }
443
444 /* regular header field in (name,value) */
445 if (unlikely(!(fields & H2_PHDR_FND_NONE))) {
446 /* no more pseudo-headers, time to build the request line */
447 sl = h2_prepare_htx_reqline(fields, phdr_val, htx, msgf);
448 if (!sl)
449 goto fail;
450 fields |= H2_PHDR_FND_NONE;
451 }
452
453 if (isteq(list[idx].n, ist("host")))
454 fields |= H2_PHDR_FND_HOST;
455
Willy Tarreaubeefaee2018-12-19 13:08:08 +0100456 if (isteq(list[idx].n, ist("content-length"))) {
Willy Tarreau4790f7c2019-01-24 11:33:02 +0100457 ret = h2_parse_cont_len_header(msgf, &list[idx].v, body_len);
Willy Tarreaubeefaee2018-12-19 13:08:08 +0100458 if (ret < 0)
459 goto fail;
460
Willy Tarreau6deb4122018-11-27 15:34:18 +0100461 sl_flags |= HTX_SL_F_CLEN;
Willy Tarreaubeefaee2018-12-19 13:08:08 +0100462 if (ret == 0)
463 continue; // skip this duplicate
Willy Tarreau6deb4122018-11-27 15:34:18 +0100464 }
465
466 /* these ones are forbidden in requests (RFC7540#8.1.2.2) */
467 if (isteq(list[idx].n, ist("connection")) ||
468 isteq(list[idx].n, ist("proxy-connection")) ||
469 isteq(list[idx].n, ist("keep-alive")) ||
470 isteq(list[idx].n, ist("upgrade")) ||
471 isteq(list[idx].n, ist("transfer-encoding")))
472 goto fail;
473
474 if (isteq(list[idx].n, ist("te")) && !isteq(list[idx].v, ist("trailers")))
475 goto fail;
476
477 /* cookie requires special processing at the end */
478 if (isteq(list[idx].n, ist("cookie"))) {
479 list[idx].n.len = -1;
480
481 if (ck < 0)
482 ck = idx;
483 else
484 list[lck].n.len = idx;
485
486 lck = idx;
487 continue;
488 }
489
490 if (!htx_add_header(htx, list[idx].n, list[idx].v))
491 goto fail;
492 }
493
494 /* RFC7540#8.1.2.1 mandates to reject response pseudo-headers (:status) */
495 if (fields & H2_PHDR_FND_STAT)
496 goto fail;
497
498 /* Let's dump the request now if not yet emitted. */
499 if (!(fields & H2_PHDR_FND_NONE)) {
500 sl = h2_prepare_htx_reqline(fields, phdr_val, htx, msgf);
501 if (!sl)
502 goto fail;
503 }
504
Christopher Fauletd0db4232021-01-22 11:46:30 +0100505 if (*msgf & H2_MSGF_BODY_TUNNEL)
506 *msgf &= ~(H2_MSGF_BODY|H2_MSGF_BODY_CL);
507
Christopher Fauletd1ac2b92020-12-02 19:12:22 +0100508 if (!(*msgf & H2_MSGF_BODY) || ((*msgf & H2_MSGF_BODY_CL) && *body_len == 0) ||
509 (*msgf & H2_MSGF_BODY_TUNNEL)) {
510 /* Request without body or tunnel requested */
Christopher Faulet44af3cf2019-02-18 10:12:56 +0100511 sl_flags |= HTX_SL_F_BODYLESS;
Christopher Fauletd1ac2b92020-12-02 19:12:22 +0100512 htx->flags |= HTX_FL_EOM;
513 }
Christopher Faulet44af3cf2019-02-18 10:12:56 +0100514
Amaury Denoyellec9a0afc2020-12-11 17:53:09 +0100515 if (*msgf & H2_MSGF_EXT_CONNECT) {
516 if (!htx_add_header(htx, ist("upgrade"), phdr_val[H2_PHDR_IDX_PROT]))
517 goto fail;
518 if (!htx_add_header(htx, ist("connection"), ist("upgrade")))
519 goto fail;
520 sl_flags |= HTX_SL_F_CONN_UPG;
521 }
522
Willy Tarreau6deb4122018-11-27 15:34:18 +0100523 /* update the start line with last detected header info */
524 sl->flags |= sl_flags;
525
526 /* complete with missing Host if needed */
527 if ((fields & (H2_PHDR_FND_HOST|H2_PHDR_FND_AUTH)) == H2_PHDR_FND_AUTH) {
528 /* missing Host field, use :authority instead */
529 if (!htx_add_header(htx, ist("host"), phdr_val[H2_PHDR_IDX_AUTH]))
530 goto fail;
531 }
532
533 /* now we may have to build a cookie list. We'll dump the values of all
534 * visited headers.
535 */
536 if (ck >= 0) {
537 uint32_t fs; // free space
538 uint32_t bs; // block size
539 uint32_t vl; // value len
Willy Tarreau164e0612018-12-18 11:00:41 +0100540 uint32_t tl; // total length
Willy Tarreau6deb4122018-11-27 15:34:18 +0100541 struct htx_blk *blk;
542
543 blk = htx_add_header(htx, ist("cookie"), list[ck].v);
544 if (!blk)
545 goto fail;
546
Willy Tarreau164e0612018-12-18 11:00:41 +0100547 tl = list[ck].v.len;
Willy Tarreau6deb4122018-11-27 15:34:18 +0100548 fs = htx_free_data_space(htx);
549 bs = htx_get_blksz(blk);
550
551 /* for each extra cookie, we'll extend the cookie's value and
552 * insert "; " before the new value.
553 */
Willy Tarreau164e0612018-12-18 11:00:41 +0100554 fs += tl; // first one is already counted
Tim Duesterhus15683552021-03-04 23:50:13 +0100555 while ((ck = list[ck].n.len) >= 0) {
Willy Tarreau6deb4122018-11-27 15:34:18 +0100556 vl = list[ck].v.len;
Willy Tarreau164e0612018-12-18 11:00:41 +0100557 tl += vl + 2;
558 if (tl > fs)
Willy Tarreau6deb4122018-11-27 15:34:18 +0100559 goto fail;
560
Christopher Faulet3e2638e2019-06-18 09:49:16 +0200561 htx_change_blk_value_len(htx, blk, tl);
Willy Tarreau6deb4122018-11-27 15:34:18 +0100562 *(char *)(htx_get_blk_ptr(htx, blk) + bs + 0) = ';';
563 *(char *)(htx_get_blk_ptr(htx, blk) + bs + 1) = ' ';
564 memcpy(htx_get_blk_ptr(htx, blk) + bs + 2, list[ck].v.ptr, vl);
565 bs += vl + 2;
Willy Tarreau6deb4122018-11-27 15:34:18 +0100566 }
567
568 }
569
570 /* now send the end of headers marker */
Christopher Faulet5be651d2021-01-22 15:28:03 +0100571 if (!htx_add_endof(htx, HTX_BLK_EOH))
572 goto fail;
Willy Tarreau6deb4122018-11-27 15:34:18 +0100573
Amaury Denoyelle03534102021-07-07 10:49:28 +0200574 /* proceed to scheme-based normalization on target-URI */
575 if (fields & H2_PHDR_FND_SCHM)
576 http_scheme_based_normalize(htx);
577
Willy Tarreau6deb4122018-11-27 15:34:18 +0100578 ret = 1;
579 return ret;
580
581 fail:
582 return -1;
583}
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200584
585/* Prepare the status line into <htx> from pseudo headers stored in <phdr[]>.
586 * <fields> indicates what was found so far. This should be called once at the
587 * detection of the first general header field or at the end of the message if
588 * no general header field was found yet. Returns the created start line on
589 * success, or NULL on failure. Upon success, <msgf> is updated with a few
590 * H2_MSGF_* flags indicating what was found while parsing.
591 */
592static struct htx_sl *h2_prepare_htx_stsline(uint32_t fields, struct ist *phdr, struct htx *htx, unsigned int *msgf)
593{
Christopher Faulet89899422020-12-07 18:24:43 +0100594 unsigned int status, flags = HTX_SL_F_NONE;
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200595 struct htx_sl *sl;
Amaury Denoyelle74162742020-12-11 17:53:05 +0100596 struct ist stat;
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200597
598 /* only :status is allowed as a pseudo header */
599 if (!(fields & H2_PHDR_FND_STAT))
600 goto fail;
601
602 if (phdr[H2_PHDR_IDX_STAT].len != 3)
603 goto fail;
604
Amaury Denoyelle74162742020-12-11 17:53:05 +0100605 /* if Extended CONNECT is used, convert status code from 200 to htx 101
606 * following rfc 8441 */
607 if (unlikely(*msgf & H2_MSGF_EXT_CONNECT) &&
608 isteq(phdr[H2_PHDR_IDX_STAT], ist("200"))) {
609 stat = ist("101");
610 status = 101;
611 }
612 else {
613 unsigned char h, t, u;
614
615 stat = phdr[H2_PHDR_IDX_STAT];
616
617 h = stat.ptr[0] - '0';
618 t = stat.ptr[1] - '0';
619 u = stat.ptr[2] - '0';
620 if (h > 9 || t > 9 || u > 9)
621 goto fail;
622 status = h * 100 + t * 10 + u;
623 }
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200624
Christopher Faulet89899422020-12-07 18:24:43 +0100625 /* 101 responses are not supported in H2, so return a error.
626 * On 1xx responses there is no ES on the HEADERS frame but there is no
627 * body. So remove the flag H2_MSGF_BODY and add H2_MSGF_RSP_1XX to
628 * notify the decoder another HEADERS frame is expected.
Ilya Shipitsinacf84592021-02-06 22:29:08 +0500629 * 204/304 response have no body by definition. So remove the flag
Christopher Faulet7d247f02020-12-02 14:26:36 +0100630 * H2_MSGF_BODY and set H2_MSGF_BODYLESS_RSP.
Amaury Denoyelle74162742020-12-11 17:53:05 +0100631 *
632 * Note however that there is a special condition for Extended CONNECT.
633 * In this case, we explicitly convert it to HTX 101 to mimic
634 * Get+Upgrade HTTP/1.1 mechanism
Christopher Faulet0b465482019-02-19 15:14:23 +0100635 */
Amaury Denoyelle74162742020-12-11 17:53:05 +0100636 if (status == 101) {
637 if (!(*msgf & H2_MSGF_EXT_CONNECT))
638 goto fail;
639 }
Christopher Faulet89899422020-12-07 18:24:43 +0100640 else if (status < 200) {
Christopher Faulet0b465482019-02-19 15:14:23 +0100641 *msgf |= H2_MSGF_RSP_1XX;
642 *msgf &= ~H2_MSGF_BODY;
643 }
Amaury Denoyelle74162742020-12-11 17:53:05 +0100644 else if (status == 204 || status == 304) {
Christopher Faulet7d247f02020-12-02 14:26:36 +0100645 *msgf &= ~H2_MSGF_BODY;
646 *msgf |= H2_MSGF_BODYLESS_RSP;
647 }
Christopher Faulet0b465482019-02-19 15:14:23 +0100648
Christopher Faulet89899422020-12-07 18:24:43 +0100649 /* Set HTX start-line flags */
650 flags |= HTX_SL_F_VER_11; // V2 in fact
651 flags |= HTX_SL_F_XFER_LEN; // xfer len always known with H2
652
Amaury Denoyelle74162742020-12-11 17:53:05 +0100653 sl = htx_add_stline(htx, HTX_BLK_RES_SL, flags, ist("HTTP/2.0"), stat, ist(""));
Christopher Faulet89899422020-12-07 18:24:43 +0100654 if (!sl)
655 goto fail;
656 sl->info.res.status = status;
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200657 return sl;
658 fail:
659 return NULL;
660}
661
662/* Takes an H2 response present in the headers list <list> terminated by a name
663 * being <NULL,0> and emits the equivalent HTX response according to the rules
664 * documented in RFC7540 #8.1.2. The output contents are emitted in <htx>, and
665 * a positive value is returned if some bytes were emitted. In case of error, a
666 * negative error code is returned.
667 *
668 * Upon success, <msgf> is filled with a few H2_MSGF_* flags indicating what
669 * was found while parsing. The caller must set it to zero in or H2_MSGF_BODY
670 * if a body is detected (!ES).
671 *
672 * The headers list <list> must be composed of :
673 * - n.name != NULL, n.len > 0 : literal header name
674 * - n.name == NULL, n.len > 0 : indexed pseudo header name number <n.len>
675 * among H2_PHDR_IDX_*
676 * - n.name ignored, n.len == 0 : end of list
677 * - in all cases except the end of list, v.name and v.len must designate a
678 * valid value.
Amaury Denoyelle74162742020-12-11 17:53:05 +0100679 *
680 * <upgrade_protocol> is only used if the htx status code is 101 indicating a
681 * response to an upgrade or h2-equivalent request.
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200682 */
Amaury Denoyelle74162742020-12-11 17:53:05 +0100683int h2_make_htx_response(struct http_hdr *list, struct htx *htx, unsigned int *msgf, unsigned long long *body_len, char *upgrade_protocol)
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200684{
685 struct ist phdr_val[H2_PHDR_NUM_ENTRIES];
686 uint32_t fields; /* bit mask of H2_PHDR_FND_* */
687 uint32_t idx;
688 int phdr;
689 int ret;
690 int i;
691 struct htx_sl *sl = NULL;
692 unsigned int sl_flags = 0;
Willy Tarreau54f53ef2019-11-22 16:02:43 +0100693 const char *ctl;
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200694
695 fields = 0;
696 for (idx = 0; list[idx].n.len != 0; idx++) {
697 if (!list[idx].n.ptr) {
698 /* this is an indexed pseudo-header */
699 phdr = list[idx].n.len;
700 }
701 else {
702 /* this can be any type of header */
Willy Tarreau146f53a2019-11-24 10:34:39 +0100703 /* RFC7540#8.1.2: upper case not allowed in header field names.
704 * #10.3: header names must be valid (i.e. match a token).
705 * For pseudo-headers we check from 2nd char and for other ones
706 * from the first char, because HTTP_IS_TOKEN() also excludes
707 * the colon.
708 */
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200709 phdr = h2_str_to_phdr(list[idx].n);
Willy Tarreau146f53a2019-11-24 10:34:39 +0100710
711 for (i = !!phdr; i < list[idx].n.len; i++)
712 if ((uint8_t)(list[idx].n.ptr[i] - 'A') < 'Z' - 'A' || !HTTP_IS_TOKEN(list[idx].n.ptr[i]))
713 goto fail;
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200714 }
715
Willy Tarreau54f53ef2019-11-22 16:02:43 +0100716 /* RFC7540#10.3: intermediaries forwarding to HTTP/1 must take care of
717 * rejecting NUL, CR and LF characters.
718 */
719 ctl = ist_find_ctl(list[idx].v);
720 if (unlikely(ctl) && has_forbidden_char(list[idx].v, ctl))
721 goto fail;
722
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200723 if (phdr > 0 && phdr < H2_PHDR_NUM_ENTRIES) {
724 /* insert a pseudo header by its index (in phdr) and value (in value) */
725 if (fields & ((1 << phdr) | H2_PHDR_FND_NONE)) {
726 if (fields & H2_PHDR_FND_NONE) {
727 /* pseudo header field after regular headers */
728 goto fail;
729 }
730 else {
731 /* repeated pseudo header field */
732 goto fail;
733 }
734 }
735 fields |= 1 << phdr;
736 phdr_val[phdr] = list[idx].v;
737 continue;
738 }
739 else if (phdr != 0) {
740 /* invalid pseudo header -- should never happen here */
741 goto fail;
742 }
743
744 /* regular header field in (name,value) */
745 if (!(fields & H2_PHDR_FND_NONE)) {
746 /* no more pseudo-headers, time to build the status line */
747 sl = h2_prepare_htx_stsline(fields, phdr_val, htx, msgf);
748 if (!sl)
749 goto fail;
750 fields |= H2_PHDR_FND_NONE;
751 }
752
Willy Tarreaubeefaee2018-12-19 13:08:08 +0100753 if (isteq(list[idx].n, ist("content-length"))) {
Willy Tarreau4790f7c2019-01-24 11:33:02 +0100754 ret = h2_parse_cont_len_header(msgf, &list[idx].v, body_len);
Willy Tarreaubeefaee2018-12-19 13:08:08 +0100755 if (ret < 0)
756 goto fail;
757
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200758 sl_flags |= HTX_SL_F_CLEN;
Willy Tarreaubeefaee2018-12-19 13:08:08 +0100759 if (ret == 0)
760 continue; // skip this duplicate
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200761 }
762
763 /* these ones are forbidden in responses (RFC7540#8.1.2.2) */
764 if (isteq(list[idx].n, ist("connection")) ||
765 isteq(list[idx].n, ist("proxy-connection")) ||
766 isteq(list[idx].n, ist("keep-alive")) ||
767 isteq(list[idx].n, ist("upgrade")) ||
768 isteq(list[idx].n, ist("transfer-encoding")))
769 goto fail;
770
771 if (!htx_add_header(htx, list[idx].n, list[idx].v))
772 goto fail;
773 }
774
775 /* RFC7540#8.1.2.1 mandates to reject request pseudo-headers */
776 if (fields & (H2_PHDR_FND_AUTH|H2_PHDR_FND_METH|H2_PHDR_FND_PATH|H2_PHDR_FND_SCHM))
777 goto fail;
778
779 /* Let's dump the request now if not yet emitted. */
780 if (!(fields & H2_PHDR_FND_NONE)) {
781 sl = h2_prepare_htx_stsline(fields, phdr_val, htx, msgf);
782 if (!sl)
783 goto fail;
Amaury Denoyelle74162742020-12-11 17:53:05 +0100784 }
785
786 if (sl->info.res.status == 101 && upgrade_protocol) {
787 if (!htx_add_header(htx, ist("connection"), ist("upgrade")))
788 goto fail;
789 if (!htx_add_header(htx, ist("upgrade"), ist(upgrade_protocol)))
790 goto fail;
791 sl_flags |= HTX_SL_F_CONN_UPG;
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200792 }
793
Amaury Denoyelle74162742020-12-11 17:53:05 +0100794 if ((*msgf & H2_MSGF_BODY_TUNNEL) &&
795 ((sl->info.res.status >= 200 && sl->info.res.status < 300) || sl->info.res.status == 101))
Christopher Fauletd0db4232021-01-22 11:46:30 +0100796 *msgf &= ~(H2_MSGF_BODY|H2_MSGF_BODY_CL);
797 else
798 *msgf &= ~H2_MSGF_BODY_TUNNEL;
799
Christopher Fauletd1ac2b92020-12-02 19:12:22 +0100800 if (!(*msgf & H2_MSGF_BODY) || ((*msgf & H2_MSGF_BODY_CL) && *body_len == 0) ||
801 (*msgf & H2_MSGF_BODY_TUNNEL)) {
Ilya Shipitsinacf84592021-02-06 22:29:08 +0500802 /* Response without body or tunnel successfully established */
Christopher Faulet44af3cf2019-02-18 10:12:56 +0100803 sl_flags |= HTX_SL_F_BODYLESS;
Christopher Fauletd1ac2b92020-12-02 19:12:22 +0100804 htx->flags |= HTX_FL_EOM;
805 }
Christopher Faulet44af3cf2019-02-18 10:12:56 +0100806
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200807 /* update the start line with last detected header info */
808 sl->flags |= sl_flags;
809
810 if ((*msgf & (H2_MSGF_BODY|H2_MSGF_BODY_TUNNEL|H2_MSGF_BODY_CL)) == H2_MSGF_BODY) {
811 /* FIXME: Do we need to signal anything when we have a body and
812 * no content-length, to have the equivalent of H1's chunked
813 * encoding?
814 */
815 }
816
817 /* now send the end of headers marker */
Christopher Faulet5be651d2021-01-22 15:28:03 +0100818 if (!htx_add_endof(htx, HTX_BLK_EOH))
819 goto fail;
Willy Tarreau1329b5b2018-10-08 14:49:20 +0200820
821 ret = 1;
822 return ret;
823
824 fail:
825 return -1;
826}
Willy Tarreau1e1f27c2019-01-03 18:39:54 +0100827
Christopher Faulet2d7c5392019-06-03 10:41:26 +0200828/* Takes an H2 headers list <list> terminated by a name being <NULL,0> and emits
829 * the equivalent HTX trailers blocks. The output contents are emitted in <htx>,
830 * and a positive value is returned if some bytes were emitted. In case of
831 * error, a negative error code is returned. The caller must have verified that
832 * the message in the buffer is compatible with receipt of trailers.
Willy Tarreau1e1f27c2019-01-03 18:39:54 +0100833 *
834 * The headers list <list> must be composed of :
835 * - n.name != NULL, n.len > 0 : literal header name
836 * - n.name == NULL, n.len > 0 : indexed pseudo header name number <n.len>
837 * among H2_PHDR_IDX_* (illegal here)
838 * - n.name ignored, n.len == 0 : end of list
839 * - in all cases except the end of list, v.name and v.len must designate a
840 * valid value.
841 */
842int h2_make_htx_trailers(struct http_hdr *list, struct htx *htx)
843{
Willy Tarreau54f53ef2019-11-22 16:02:43 +0100844 const char *ctl;
Willy Tarreau1e1f27c2019-01-03 18:39:54 +0100845 uint32_t idx;
Willy Tarreau1e1f27c2019-01-03 18:39:54 +0100846 int i;
847
Willy Tarreau1e1f27c2019-01-03 18:39:54 +0100848 for (idx = 0; list[idx].n.len != 0; idx++) {
849 if (!list[idx].n.ptr) {
850 /* This is an indexed pseudo-header (RFC7540#8.1.2.1) */
851 goto fail;
852 }
853
Willy Tarreau146f53a2019-11-24 10:34:39 +0100854 /* RFC7540#8.1.2: upper case not allowed in header field names.
855 * #10.3: header names must be valid (i.e. match a token). This
856 * also catches pseudo-headers which are forbidden in trailers.
857 */
Willy Tarreau1e1f27c2019-01-03 18:39:54 +0100858 for (i = 0; i < list[idx].n.len; i++)
Willy Tarreau146f53a2019-11-24 10:34:39 +0100859 if ((uint8_t)(list[idx].n.ptr[i] - 'A') < 'Z' - 'A' || !HTTP_IS_TOKEN(list[idx].n.ptr[i]))
Willy Tarreau1e1f27c2019-01-03 18:39:54 +0100860 goto fail;
861
Willy Tarreau1e1f27c2019-01-03 18:39:54 +0100862 /* these ones are forbidden in trailers (RFC7540#8.1.2.2) */
863 if (isteq(list[idx].n, ist("host")) ||
864 isteq(list[idx].n, ist("content-length")) ||
865 isteq(list[idx].n, ist("connection")) ||
866 isteq(list[idx].n, ist("proxy-connection")) ||
867 isteq(list[idx].n, ist("keep-alive")) ||
868 isteq(list[idx].n, ist("upgrade")) ||
869 isteq(list[idx].n, ist("te")) ||
870 isteq(list[idx].n, ist("transfer-encoding")))
871 goto fail;
872
Willy Tarreau54f53ef2019-11-22 16:02:43 +0100873 /* RFC7540#10.3: intermediaries forwarding to HTTP/1 must take care of
874 * rejecting NUL, CR and LF characters.
875 */
876 ctl = ist_find_ctl(list[idx].v);
877 if (unlikely(ctl) && has_forbidden_char(list[idx].v, ctl))
878 goto fail;
879
Christopher Faulet2d7c5392019-06-03 10:41:26 +0200880 if (!htx_add_trailer(htx, list[idx].n, list[idx].v))
881 goto fail;
Willy Tarreau1e1f27c2019-01-03 18:39:54 +0100882 }
883
Christopher Faulet2d7c5392019-06-03 10:41:26 +0200884 if (!htx_add_endof(htx, HTX_BLK_EOT))
Willy Tarreau1e1f27c2019-01-03 18:39:54 +0100885 goto fail;
886
Willy Tarreau1e1f27c2019-01-03 18:39:54 +0100887 return 1;
888
889 fail:
890 return -1;
891}