Willy Tarreau | 306924e | 2017-09-21 14:25:39 +0200 | [diff] [blame] | 1 | /* |
| 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 Tarreau | a1bd1fa | 2019-03-29 17:26:33 +0100 | [diff] [blame] | 30 | #include <inttypes.h> |
Willy Tarreau | 306924e | 2017-09-21 14:25:39 +0200 | [diff] [blame] | 31 | #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 | */ |
| 36 | struct 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 | */ |
| 44 | static 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 Tarreau | e2c418e | 2018-09-14 17:32:05 +0200 | [diff] [blame] | 50 | /* 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 | */ |
| 53 | static 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 Tarreau | 306924e | 2017-09-21 14:25:39 +0200 | [diff] [blame] | 67 | #endif /* _COMMON_HTTP_HDR_H */ |