blob: 0521b11a96af650d3a05cb719b9bd4b90112ba5a [file] [log] [blame]
Willy Tarreauffca7362016-12-13 18:25:15 +01001/*
2 * include/common/h2.h
3 * This file contains types and macros used for the HTTP/2 protocol
4 *
5 * Copyright (C) 2000-2017 Willy Tarreau - w@1wt.eu
6 * Copyright (C) 2017 HAProxy Technologies
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation, version 2.1
11 * exclusively.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#ifndef _COMMON_H2_H
24#define _COMMON_H2_H
25
26#include <common/config.h>
27
28
29/* frame types, from the standard */
30enum h2_ft {
31 H2_FT_DATA = 0x00, // RFC7540 #6.1
32 H2_FT_HEADERS = 0x01, // RFC7540 #6.2
33 H2_FT_PRIORITY = 0x02, // RFC7540 #6.3
34 H2_FT_RST_STREAM = 0x03, // RFC7540 #6.4
35 H2_FT_SETTINGS = 0x04, // RFC7540 #6.5
36 H2_FT_PUSH_PROMISE = 0x05, // RFC7540 #6.6
37 H2_FT_PING = 0x06, // RFC7540 #6.7
38 H2_FT_GOAWAY = 0x07, // RFC7540 #6.8
39 H2_FT_WINDOW_UPDATE = 0x08, // RFC7540 #6.9
40 H2_FT_CONTINUATION = 0x09, // RFC7540 #6.10
41 H2_FT_ENTRIES /* must be last */
42} __attribute__((packed));
43
44/* flags defined for each frame type */
45
46// RFC7540 #6.1
47#define H2_F_DATA_END_STREAM 0x01
48#define H2_F_DATA_PADDED 0x08
49
50// RFC7540 #6.2
51#define H2_F_HEADERS_END_STREAM 0x01
52#define H2_F_HEADERS_END_HEADERS 0x04
53#define H2_F_HEADERS_PADDED 0x08
54#define H2_F_HEADERS_PRIORITY 0x20
55
56// RFC7540 #6.3 : PRIORITY defines no flags
57// RFC7540 #6.4 : RST_STREAM defines no flags
58
59// RFC7540 #6.5
60#define H2_F_SETTINGS_ACK 0x01
61
62// RFC7540 #6.6
63#define H2_F_PUSH_PROMISE_END_HEADERS 0x04
64#define H2_F_PUSH_PROMISE_PADDED 0x08
65
66// RFC7540 #6.7
67#define H2_F_PING_ACK 0x01
68
69// RFC7540 #6.8 : GOAWAY defines no flags
70// RFC7540 #6.9 : WINDOW_UPDATE defines no flags
71
72/* HTTP/2 error codes - RFC7540 #7 */
73enum h2_err {
74 H2_ERR_NO_ERROR = 0x0,
75 H2_ERR_PROTOCOL_ERROR = 0x1,
76 H2_ERR_INTERNAL_ERROR = 0x2,
77 H2_ERR_FLOW_CONTROL_ERROR = 0x3,
78 H2_ERR_SETTINGS_TIMEOUT = 0x4,
79 H2_ERR_STREAM_CLOSED = 0x5,
80 H2_ERR_FRAME_SIZE_ERROR = 0x6,
81 H2_ERR_REFUSED_STREAM = 0x7,
82 H2_ERR_CANCEL = 0x8,
83 H2_ERR_COMPRESSION_ERROR = 0x9,
84 H2_ERR_CONNECT_ERROR = 0xa,
85 H2_ERR_ENHANCE_YOUR_CALM = 0xb,
86 H2_ERR_INADEQUATE_SECURITY = 0xc,
87 H2_ERR_HTTP_1_1_REQUIRED = 0xd,
88} __attribute__((packed));
89
90// RFC7540 #11.3 : Settings Registry
91#define H2_SETTINGS_HEADER_TABLE_SIZE 0x0001
92#define H2_SETTINGS_ENABLE_PUSH 0x0002
93#define H2_SETTINGS_MAX_CONCURRENT_STREAMS 0x0003
94#define H2_SETTINGS_INITIAL_WINDOW_SIZE 0x0004
95#define H2_SETTINGS_MAX_FRAME_SIZE 0x0005
96#define H2_SETTINGS_MAX_HEADER_LIST_SIZE 0x0006
97
98
99/* some protocol constants */
100
101// PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n
102#define H2_CONN_PREFACE \
103 "\x50\x52\x49\x20\x2a\x20\x48\x54" \
104 "\x54\x50\x2f\x32\x2e\x30\x0d\x0a" \
105 "\x0d\x0a\x53\x4d\x0d\x0a\x0d\x0a"
106
107/*
108 * Some helpful debugging functions.
109 */
110
111/* returns the frame type as a string */
112static inline const char *h2_ft_str(int type)
113{
114 switch (type) {
115 case H2_FT_DATA : return "DATA";
116 case H2_FT_HEADERS : return "HEADERS";
117 case H2_FT_PRIORITY : return "PRIORITY";
118 case H2_FT_RST_STREAM : return "RST_STREAM";
119 case H2_FT_SETTINGS : return "SETTINGS";
120 case H2_FT_PUSH_PROMISE : return "PUSH_PROMISE";
121 case H2_FT_PING : return "PING";
122 case H2_FT_GOAWAY : return "GOAWAY";
123 case H2_FT_WINDOW_UPDATE : return "WINDOW_UPDATE";
124 default : return "_UNKNOWN_";
125 }
126}
127
128#endif /* _COMMON_H2_H */
129
130/*
131 * Local variables:
132 * c-indent-level: 8
133 * c-basic-offset: 8
134 * End:
135 */