2 * Official static header table for HPACK
3 * +-------+-----------------------------+---------------+
8 | 5 | :path | /index.html |
10 | 7 | :scheme | https |
13 | 10 | :status | 206 |
14 | 11 | :status | 304 |
15 | 12 | :status | 400 |
16 | 13 | :status | 404 |
17 | 14 | :status | 500 |
18 | 15 | accept-charset | |
19 | 16 | accept-encoding | gzip, deflate |
20 | 17 | accept-language | |
21 | 18 | accept-ranges | |
23 | 20 | access-control-allow-origin | |
26 | 23 | authorization | |
27 | 24 | cache-control | |
28 | 25 | content-disposition | |
29 | 26 | content-encoding | |
30 | 27 | content-language | |
31 | 28 | content-length | |
32 | 29 | content-location | |
33 | 30 | content-range | |
34 | 31 | content-type | |
43 | 40 | if-modified-since | |
44 | 41 | if-none-match | |
46 | 43 | if-unmodified-since | |
47 | 44 | last-modified | |
50 | 47 | max-forwards | |
51 | 48 | proxy-authenticate | |
52 | 49 | proxy-authorization | |
56 | 53 | retry-after | |
59 | 56 | strict-transport-security | |
60 | 57 | transfer-encoding | |
64 | 61 | www-authenticate | |
65 +-------+-----------------------------+---------------+
68 static const unsigned char static_token[] = {
70 WSI_TOKEN_HTTP_COLON_AUTHORITY,
71 WSI_TOKEN_HTTP_COLON_METHOD,
72 WSI_TOKEN_HTTP_COLON_METHOD,
73 WSI_TOKEN_HTTP_COLON_PATH,
74 WSI_TOKEN_HTTP_COLON_PATH,
75 WSI_TOKEN_HTTP_COLON_SCHEME,
76 WSI_TOKEN_HTTP_COLON_SCHEME,
77 WSI_TOKEN_HTTP_COLON_STATUS,
78 WSI_TOKEN_HTTP_COLON_STATUS,
79 WSI_TOKEN_HTTP_COLON_STATUS,
80 WSI_TOKEN_HTTP_COLON_STATUS,
81 WSI_TOKEN_HTTP_COLON_STATUS,
82 WSI_TOKEN_HTTP_COLON_STATUS,
83 WSI_TOKEN_HTTP_COLON_STATUS,
84 WSI_TOKEN_HTTP_ACCEPT_CHARSET,
85 WSI_TOKEN_HTTP_ACCEPT_ENCODING,
86 WSI_TOKEN_HTTP_ACCEPT_LANGUAGE,
87 WSI_TOKEN_HTTP_ACCEPT_RANGES,
88 WSI_TOKEN_HTTP_ACCEPT,
89 WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN,
92 WSI_TOKEN_HTTP_AUTHORIZATION,
93 WSI_TOKEN_HTTP_CACHE_CONTROL,
94 WSI_TOKEN_HTTP_CONTENT_DISPOSITION,
95 WSI_TOKEN_HTTP_CONTENT_ENCODING,
96 WSI_TOKEN_HTTP_CONTENT_LANGUAGE,
97 WSI_TOKEN_HTTP_CONTENT_LENGTH,
98 WSI_TOKEN_HTTP_CONTENT_LOCATION,
99 WSI_TOKEN_HTTP_CONTENT_RANGE,
100 WSI_TOKEN_HTTP_CONTENT_TYPE,
101 WSI_TOKEN_HTTP_COOKIE,
104 WSI_TOKEN_HTTP_EXPECT,
105 WSI_TOKEN_HTTP_EXPIRES,
108 WSI_TOKEN_HTTP_IF_MATCH,
109 WSI_TOKEN_HTTP_IF_MODIFIED_SINCE,
110 WSI_TOKEN_HTTP_IF_NONE_MATCH,
111 WSI_TOKEN_HTTP_IF_RANGE,
112 WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE,
113 WSI_TOKEN_HTTP_LAST_MODIFIED,
115 WSI_TOKEN_HTTP_LOCATION,
116 WSI_TOKEN_HTTP_MAX_FORWARDS,
117 WSI_TOKEN_HTTP_PROXY_AUTHENTICATE,
118 WSI_TOKEN_HTTP_PROXY_AUTHORIZATION,
119 WSI_TOKEN_HTTP_RANGE,
120 WSI_TOKEN_HTTP_REFERER,
121 WSI_TOKEN_HTTP_REFRESH,
122 WSI_TOKEN_HTTP_RETRY_AFTER,
123 WSI_TOKEN_HTTP_SERVER,
124 WSI_TOKEN_HTTP_SET_COOKIE,
125 WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY,
126 WSI_TOKEN_HTTP_TRANSFER_ENCODING,
127 WSI_TOKEN_HTTP_USER_AGENT,
130 WSI_TOKEN_HTTP_WWW_AUTHENTICATE,
133 static const char * const http2_canned[] = {
154 #include "huftable.h"
156 int lextable_decode(int pos, char c)
160 if (lextable_terms[q >> 3] & (1 << (q & 7))) /* terminal */
161 return lextable[q] | 0x8000;
163 return pos + (lextable[q] << 1);
166 static int lws_add_header(int header, const char *payload, int len)
168 wsi->u.ah.frag_index[header]
171 int lws_hpack_interpret(struct libwebsocket *wsi, unsigned char c)
173 switch (wsi->u.http2.hpack) {
175 if (c & 0x80) { /* indexed header field only */
176 wsi->u.http2.header_index = c & 0x7f;
177 /* stay at same state */
180 if (c & 0x40) { /* literal header incr idx */
181 if (c == 0x40) { /* literal name */
182 wsi->u.http2.header_index = 0;
184 wsi->u.http2.hpack = HPKS_HLEN;
188 wsi->u.http2.header_index = c & 0x3f;
189 wsi->u.http2.hpack = HPKS_HLEN;
193 case 0: /* literal header without indexing */
194 if (c == 0) { /* literal name */
195 wsi->u.http2.hpack = HPKS_NAME_HLEN;
199 wsi->u.http2.header_index = c & 0xf;
200 wsi->u.http2.hpack = HPKS_VALUE_HLEN;
202 case 0x10: /* literal header never indexed */
203 if (c == 0x10) { /* literal name */
204 wsi->u.http2.header_index = 0;
205 wsi->u.http2.hpack = HPKS_NAME_HLEN;
209 wsi->u.http2.header_index = c & 0xf;
210 wsi->u.http2.hpack = HPKS_NAME_HLEN;
213 case 0x30: /* header table size update */
215 /* stay at same state */
220 wsi->u.http2.huff = !!(c & 0x80);
221 wsi->u.http2.hpack_len = c & 0x7f;
222 if (wsi->u.http2.hpack_len < 127) {
223 wsi->u.http2.hpack = HPKS_NAME_DATA;
226 wsi->u.http2.hpack_m = 0;
227 wsi->u.http2.hpack = HPKS_NAME_HLEN_EXT;
230 wsi->u.http2.hpack_len += (c & 0x7f) << wsi->u.http2.hpack_m;
231 wsi->u.http2.hpack_m += 7;
233 wsi->u.http2.hpack = HPKS_NAME_DATA;