blob: ffca828d22c029f3f16077b20b4b500335f4e0cf [file] [log] [blame]
Willy Tarreau306924e2017-09-21 14:25:39 +02001/*
2 * HTTP header management (new model) - type definitions
3 *
4 * Copyright (C) 2014-2017 Willy Tarreau <willy@haproxy.org>
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#ifndef _COMMON_HTTP_HDR_H
28#define _COMMON_HTTP_HDR_H
29
Willy Tarreaua1bd1fa2019-03-29 17:26:33 +010030#include <inttypes.h>
Willy Tarreau306924e2017-09-21 14:25:39 +020031#include <common/ist.h>
32
33/* a header field made of a name and a value. Such structure stores 4 longs so
34 * it takes 16 bytes on 32-bit systems and 32 bytes on 64-bit systems.
35 */
36struct http_hdr {
37 struct ist n; /* name */
38 struct ist v; /* value */
39};
40
41/* sets an http_hdr <hdr> to name <n> and value <v>. Useful to avoid casts in
42 * immediate assignments.
43 */
44static inline void http_set_hdr(struct http_hdr *hdr, const struct ist n, const struct ist v)
45{
46 hdr->n = n;
47 hdr->v = v;
48}
49
Willy Tarreaue2c418e2018-09-14 17:32:05 +020050/* removes all occurrences of header name <n> in list <hdr> and returns the new count. The
51 * list must be terminated by the empty header.
52 */
53static inline int http_del_hdr(struct http_hdr *hdr, const struct ist n)
54{
55 int src = 0, dst = 0;
56
57 do {
58 if (!isteqi(hdr[src].n, n)) {
59 if (src != dst)
60 hdr[dst] = hdr[src];
61 dst++;
62 }
63 } while (hdr[src++].n.len);
64
65 return dst;
66}
Willy Tarreau306924e2017-09-21 14:25:39 +020067#endif /* _COMMON_HTTP_HDR_H */