blob: 8f3280fa08a4e66a11485ff24cc9e6bae65b6ca7 [file] [log] [blame]
Christopher Fauleta3d2a162018-10-22 08:59:39 +02001/*
2 * include/types/htx.h
3 * This file contains the internal HTTP definitions.
4 *
5 * Copyright (C) 2018 HAProxy Technologies, Christopher Faulet <cfaulet@haproxy.com>
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, version 2.1
10 * exclusively.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#ifndef _TYPES_HTX_H
23#define _TYPES_HTX_H
24
25#include <common/ist.h>
26#include <types/sample.h>
27
28/*
29 * The internal representation of an HTTP message is a contiguous array
30 * containing both the blocks (htx_blk) and their contents. Blocks are stored
31 * starting from the end of the array while their contents are stored at the
32 * beginning.
33 *
34 * As data are sent to the peer, blocks and contents are released at the
35 * edges. This free space is reused when no more space left. So blocks and
36 * contents may wrap, not necessarily the same time.
37 *
38 * An HTTP block is as well a header as a body part or a trailer part. For all
39 * these types of block, a content is attached to the block. It can also be a
40 * mark, like the end-of-headers or end-of-message. For these blocks, there is
41 * no content but it count for a byte. It is important to not skip it when data
42 * are forwarded. An HTTP block is composed of 2 fields:
43 *
44 * - .info : It a 32 bits field containing the block's type on 4 bits
45 * followed by content' length. See below for details.
46 *
47 * - .addr : The content's address, if any, relatively to the beginning the
48 * array used to store the HTTP message itself.
49 *
50 * htx_blk.info representation:
51 *
52 * 0b 0000 0000 0000 0000 0000 0000 0000 0000
53 * ---- ------------------------ ---------
54 * type value (1 MB max) name length (header)
55 * ----------------------------------
56 * data length (256 MB max)
57 * (body, method, path, version, status, reason, trailers)
58 *
59 * types:
60 * - 0000 = request start-line
61 * - 0001 = response start-line
62 * - 0010 = header
63 * - 0011 = pseudo-header ou "special" header
64 * - 0100 = end-of-headers
65 * - 0101 = data
66 * - 0110 = end-of-data
67 * - 0111 = trailer
68 * - 1000 = end-of-message
69 * ...
70 * - 1101 = out-of-band
71 * - 1110 = error
72 * - 1111 = unused
73 *
74 */
75
76/* HTX flags */
77#define HTX_FL_NONE 0x00000000
78#define HTX_FL_PARSING_ERROR 0x00000001
79
80
81/* Pseudo header types (max 255). */
82enum htx_phdr_type {
83 HTX_PHDR_UNKNOWN = 0,
84 HTX_PHDR_SIZE,
85};
86
87/* HTTP block's type (max 15). */
88enum htx_blk_type {
89 HTX_BLK_REQ_SL = 0, /* Request start-line */
90 HTX_BLK_RES_SL = 1, /* Response start-line */
91 HTX_BLK_HDR = 2, /* header name/value block */
92 HTX_BLK_PHDR = 3, /* pseudo header block */
93 HTX_BLK_EOH = 4, /* end-of-headers block */
94 HTX_BLK_DATA = 5, /* data block */
95 HTX_BLK_EOD = 6, /* end-of-data block */
96 HTX_BLK_TLR = 7, /* trailer name/value block */
97 HTX_BLK_EOM = 8, /* end-of-message block */
98 /* 9 .. 13 unused */
99 HTX_BLK_OOB = 14, /* Out of band block, don't alter the parser */
100 HTX_BLK_UNUSED = 15, /* unused/removed block */
101};
102
103/* One HTTP block descriptor */
104struct htx_blk {
105 uint32_t addr; /* relative storage address of a data block */
106 uint32_t info; /* information about data stored */
107};
108
109struct htx_ret {
110 int32_t ret;
111 struct htx_blk *blk;
112};
113
114union htx_sl {
115 struct {
116 enum http_meth_t meth; /* method */
117 int m_len; /* METHOD length */
118 int u_len; /* URI length */
119 int v_len; /* VERSION length */
120 char l[0];
121 } rq; /* request line : field, length, data */
122 struct {
123 uint16_t status; /* status code */
124 int v_len; /* VERSION length */
125 int c_len; /* CODE length */
126 int r_len; /* REASON length */
127 char l[0];
128 } st; /* status line : field, length, data */
129};
130
131/* Internal representation of an HTTP message */
132struct htx {
133 uint32_t size; /* the array size, in bytes, used to store the HTTP message itself */
134 uint32_t data; /* the data size, in bytes. To known to total size used by all allocated
135 * blocks (blocks and their contents), you need to add size used by blocks,
136 * i.e. [ used * sizeof(struct htx_blk *) ] */
137
138 uint32_t used; /* number of blocks in use */
139 uint32_t tail; /* last inserted block */
140 uint32_t front; /* block's position of the first content before the blocks table */
141 uint32_t wrap; /* the position were the blocks table wraps, if any */
142
143 uint64_t extra; /* known bytes amount remaining to receive */
144 uint32_t flags; /* HTX_FL_* */
145
146 struct htx_blk blocks[0]; /* Blocks representing the HTTP message itself */
147};
148
149#endif /* _TYPES_HTX_H */
150
151/*
152 * Local variables:
153 * c-indent-level: 8
154 * c-basic-offset: 8
155 * End:
156 */