Mercurial > hg > nginx
annotate src/http/v3/ngx_http_v3_parse.c @ 8518:f9b1a4e52597 quic
QUIC: changed c->quic->pto_count type to ngx_uint_t.
This field is served as a simple counter for PTO backoff.
author | Sergey Kandaurov <pluknet@nginx.com> |
---|---|
date | Wed, 19 Aug 2020 15:58:03 +0300 |
parents | 0596fe1aee16 |
children | d70a38acaea0 |
rev | line source |
---|---|
8226 | 1 |
2 /* | |
3 * Copyright (C) Roman Arutyunyan | |
4 * Copyright (C) Nginx, Inc. | |
5 */ | |
6 | |
7 | |
8 #include <ngx_config.h> | |
9 #include <ngx_core.h> | |
10 #include <ngx_http.h> | |
11 | |
12 | |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
13 static ngx_int_t ngx_http_v3_parse_lookup(ngx_connection_t *c, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
14 ngx_uint_t dynamic, ngx_uint_t index, ngx_str_t *name, ngx_str_t *value); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
15 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
16 |
8226 | 17 ngx_int_t |
18 ngx_http_v3_parse_varlen_int(ngx_connection_t *c, | |
19 ngx_http_v3_parse_varlen_int_t *st, u_char ch) | |
20 { | |
21 enum { | |
22 sw_start = 0, | |
23 sw_length_2, | |
24 sw_length_3, | |
25 sw_length_4, | |
26 sw_length_5, | |
27 sw_length_6, | |
28 sw_length_7, | |
29 sw_length_8 | |
30 }; | |
31 | |
32 switch (st->state) { | |
33 | |
34 case sw_start: | |
35 | |
36 st->value = ch; | |
37 if (st->value & 0xc0) { | |
38 st->state = sw_length_2; | |
39 break; | |
40 } | |
41 | |
42 goto done; | |
43 | |
44 case sw_length_2: | |
45 | |
46 st->value = (st->value << 8) + ch; | |
47 if ((st->value & 0xc000) == 0x4000) { | |
48 st->value &= 0x3fff; | |
49 goto done; | |
50 } | |
51 | |
52 st->state = sw_length_3; | |
53 break; | |
54 | |
55 case sw_length_4: | |
56 | |
57 st->value = (st->value << 8) + ch; | |
58 if ((st->value & 0xc0000000) == 0x80000000) { | |
59 st->value &= 0x3fffffff; | |
60 goto done; | |
61 } | |
62 | |
63 st->state = sw_length_5; | |
64 break; | |
65 | |
66 case sw_length_3: | |
67 case sw_length_5: | |
68 case sw_length_6: | |
69 case sw_length_7: | |
70 | |
71 st->value = (st->value << 8) + ch; | |
72 st->state++; | |
73 break; | |
74 | |
75 case sw_length_8: | |
76 | |
77 st->value = (st->value << 8) + ch; | |
78 st->value &= 0x3fffffffffffffff; | |
79 goto done; | |
80 } | |
81 | |
82 return NGX_AGAIN; | |
83 | |
84 done: | |
85 | |
86 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
87 "http3 parse varlen int %uL", st->value); | |
88 | |
89 st->state = sw_start; | |
90 return NGX_DONE; | |
91 } | |
92 | |
93 | |
94 ngx_int_t | |
95 ngx_http_v3_parse_prefix_int(ngx_connection_t *c, | |
96 ngx_http_v3_parse_prefix_int_t *st, ngx_uint_t prefix, u_char ch) | |
97 { | |
8455
b0e81f49d7c0
HTTP/3: fixed prefixed integer encoding and decoding.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
98 ngx_uint_t mask; |
8226 | 99 enum { |
100 sw_start = 0, | |
101 sw_value | |
102 }; | |
103 | |
104 switch (st->state) { | |
105 | |
106 case sw_start: | |
107 | |
8455
b0e81f49d7c0
HTTP/3: fixed prefixed integer encoding and decoding.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
108 mask = (1 << prefix) - 1; |
b0e81f49d7c0
HTTP/3: fixed prefixed integer encoding and decoding.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
109 st->value = ch & mask; |
8226 | 110 |
8455
b0e81f49d7c0
HTTP/3: fixed prefixed integer encoding and decoding.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
111 if (st->value != mask) { |
8226 | 112 goto done; |
113 } | |
114 | |
8455
b0e81f49d7c0
HTTP/3: fixed prefixed integer encoding and decoding.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
115 st->shift = 0; |
8226 | 116 st->state = sw_value; |
117 break; | |
118 | |
119 case sw_value: | |
120 | |
8463
2576485b93d4
HTTP/3: fixed overflow in prefixed integer parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8462
diff
changeset
|
121 st->value += (uint64_t) (ch & 0x7f) << st->shift; |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
122 |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
123 if (st->shift == 56 |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
124 && ((ch & 0x80) || (st->value & 0xc000000000000000))) |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
125 { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
126 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
127 "client exceeded integer size limit"); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
128 return NGX_HTTP_V3_ERR_EXCESSIVE_LOAD; |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
129 } |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
130 |
8226 | 131 if (ch & 0x80) { |
8455
b0e81f49d7c0
HTTP/3: fixed prefixed integer encoding and decoding.
Roman Arutyunyan <arut@nginx.com>
parents:
8454
diff
changeset
|
132 st->shift += 7; |
8226 | 133 break; |
134 } | |
135 | |
136 goto done; | |
137 } | |
138 | |
139 return NGX_AGAIN; | |
140 | |
141 done: | |
142 | |
143 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
144 "http3 parse prefix int %uL", st->value); | |
145 | |
146 st->state = sw_start; | |
147 return NGX_DONE; | |
148 } | |
149 | |
150 | |
151 ngx_int_t | |
152 ngx_http_v3_parse_headers(ngx_connection_t *c, ngx_http_v3_parse_headers_t *st, | |
153 u_char ch) | |
154 { | |
155 ngx_int_t rc; | |
156 enum { | |
157 sw_start = 0, | |
158 sw_length, | |
159 sw_prefix, | |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
160 sw_verify, |
8226 | 161 sw_header_rep, |
162 sw_done | |
163 }; | |
164 | |
165 switch (st->state) { | |
166 | |
167 case sw_start: | |
168 | |
169 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse headers"); | |
170 | |
171 if (ch != NGX_HTTP_V3_FRAME_HEADERS) { | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
172 return NGX_HTTP_V3_ERR_FRAME_UNEXPECTED; |
8226 | 173 } |
174 | |
175 st->state = sw_length; | |
176 break; | |
177 | |
178 case sw_length: | |
179 | |
8466
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
180 rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, ch); |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
181 if (rc != NGX_DONE) { |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
182 return rc; |
8226 | 183 } |
184 | |
185 st->length = st->vlint.value; | |
186 | |
187 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
188 "http3 parse headers len:%ui", st->length); | |
189 | |
190 st->state = sw_prefix; | |
191 break; | |
192 | |
193 case sw_prefix: | |
194 | |
195 if (st->length-- == 0) { | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
196 return NGX_HTTP_V3_ERR_FRAME_ERROR; |
8226 | 197 } |
198 | |
199 rc = ngx_http_v3_parse_header_block_prefix(c, &st->prefix, ch); | |
200 if (rc != NGX_DONE) { | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
201 return rc; |
8226 | 202 } |
203 | |
204 if (st->length == 0) { | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
205 return NGX_HTTP_V3_ERR_FRAME_ERROR; |
8226 | 206 } |
207 | |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
208 st->state = sw_verify; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
209 break; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
210 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
211 case sw_verify: |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
212 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
213 rc = ngx_http_v3_check_insert_count(c, st->prefix.insert_count); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
214 if (rc != NGX_OK) { |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
215 return rc; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
216 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
217 |
8226 | 218 st->state = sw_header_rep; |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
219 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
220 /* fall through */ |
8226 | 221 |
222 case sw_header_rep: | |
223 | |
224 rc = ngx_http_v3_parse_header_rep(c, &st->header_rep, st->prefix.base, | |
225 ch); | |
226 | |
8467
e02250b55b17
HTTP/3: simplified handling return codes from parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8466
diff
changeset
|
227 if (--st->length == 0 && rc == NGX_AGAIN) { |
e02250b55b17
HTTP/3: simplified handling return codes from parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8466
diff
changeset
|
228 return NGX_HTTP_V3_ERR_FRAME_ERROR; |
8226 | 229 } |
230 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
231 if (rc != NGX_DONE) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
232 return rc; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
233 } |
8226 | 234 |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
235 if (st->length == 0) { |
8226 | 236 goto done; |
237 } | |
238 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
239 return NGX_OK; |
8226 | 240 } |
241 | |
242 return NGX_AGAIN; | |
243 | |
244 done: | |
245 | |
246 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse headers done"); | |
247 | |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
248 if (st->prefix.insert_count > 0) { |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
249 if (ngx_http_v3_client_ack_header(c, c->qs->id) != NGX_OK) { |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
250 return NGX_ERROR; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
251 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
252 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
253 |
8226 | 254 st->state = sw_start; |
255 return NGX_DONE; | |
256 } | |
257 | |
258 | |
259 ngx_int_t | |
260 ngx_http_v3_parse_header_block_prefix(ngx_connection_t *c, | |
261 ngx_http_v3_parse_header_block_prefix_t *st, u_char ch) | |
262 { | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
263 ngx_int_t rc; |
8226 | 264 enum { |
265 sw_start = 0, | |
266 sw_req_insert_count, | |
267 sw_delta_base, | |
268 sw_read_delta_base | |
269 }; | |
270 | |
271 switch (st->state) { | |
272 | |
273 case sw_start: | |
274 | |
275 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
276 "http3 parse header block prefix"); | |
277 | |
278 st->state = sw_req_insert_count; | |
279 | |
280 /* fall through */ | |
281 | |
282 case sw_req_insert_count: | |
283 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
284 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 8, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
285 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
286 return rc; |
8226 | 287 } |
288 | |
289 st->insert_count = st->pint.value; | |
290 st->state = sw_delta_base; | |
291 break; | |
292 | |
293 case sw_delta_base: | |
294 | |
295 st->sign = (ch & 0x80) ? 1 : 0; | |
296 st->state = sw_read_delta_base; | |
297 | |
298 /* fall through */ | |
299 | |
300 case sw_read_delta_base: | |
301 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
302 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
303 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
304 return rc; |
8226 | 305 } |
306 | |
307 st->delta_base = st->pint.value; | |
308 goto done; | |
309 } | |
310 | |
311 return NGX_AGAIN; | |
312 | |
313 done: | |
314 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
315 rc = ngx_http_v3_decode_insert_count(c, &st->insert_count); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
316 if (rc != NGX_OK) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
317 return rc; |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
318 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
319 |
8226 | 320 if (st->sign) { |
321 st->base = st->insert_count - st->delta_base - 1; | |
322 } else { | |
323 st->base = st->insert_count + st->delta_base; | |
324 } | |
325 | |
326 ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
327 "http3 parse header block prefix done " | |
8478
d2f716e668e8
Fixed format specifiers.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8467
diff
changeset
|
328 "insert_count:%ui, sign:%ui, delta_base:%ui, base:%ui", |
8226 | 329 st->insert_count, st->sign, st->delta_base, st->base); |
330 | |
331 st->state = sw_start; | |
332 return NGX_DONE; | |
333 } | |
334 | |
335 | |
336 ngx_int_t | |
337 ngx_http_v3_parse_header_rep(ngx_connection_t *c, | |
338 ngx_http_v3_parse_header_rep_t *st, ngx_uint_t base, u_char ch) | |
339 { | |
340 ngx_int_t rc; | |
341 enum { | |
342 sw_start = 0, | |
343 sw_header_ri, | |
344 sw_header_lri, | |
345 sw_header_l, | |
346 sw_header_pbi, | |
347 sw_header_lpbi | |
348 }; | |
349 | |
350 if (st->state == sw_start) { | |
351 | |
352 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
353 "http3 parse header representation"); | |
354 | |
355 ngx_memzero(&st->header, sizeof(ngx_http_v3_parse_header_t)); | |
356 | |
357 st->header.base = base; | |
358 | |
359 if (ch & 0x80) { | |
360 /* Indexed Header Field */ | |
361 | |
362 st->state = sw_header_ri; | |
363 | |
364 } else if (ch & 0x40) { | |
365 /* Literal Header Field With Name Reference */ | |
366 | |
367 st->state = sw_header_lri; | |
368 | |
369 } else if (ch & 0x20) { | |
370 /* Literal Header Field Without Name Reference */ | |
371 | |
372 st->state = sw_header_l; | |
373 | |
374 } else if (ch & 0x10) { | |
375 /* Indexed Header Field With Post-Base Index */ | |
376 | |
377 st->state = sw_header_pbi; | |
378 | |
379 } else { | |
380 /* Literal Header Field With Post-Base Name Reference */ | |
381 | |
382 st->state = sw_header_lpbi; | |
383 } | |
384 } | |
385 | |
386 switch (st->state) { | |
387 | |
388 case sw_header_ri: | |
389 rc = ngx_http_v3_parse_header_ri(c, &st->header, ch); | |
390 break; | |
391 | |
392 case sw_header_lri: | |
393 rc = ngx_http_v3_parse_header_lri(c, &st->header, ch); | |
394 break; | |
395 | |
396 case sw_header_l: | |
397 rc = ngx_http_v3_parse_header_l(c, &st->header, ch); | |
398 break; | |
399 | |
400 case sw_header_pbi: | |
401 rc = ngx_http_v3_parse_header_pbi(c, &st->header, ch); | |
402 break; | |
403 | |
404 case sw_header_lpbi: | |
405 rc = ngx_http_v3_parse_header_lpbi(c, &st->header, ch); | |
406 break; | |
407 | |
408 default: | |
409 rc = NGX_OK; | |
410 } | |
411 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
412 if (rc != NGX_DONE) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
413 return rc; |
8226 | 414 } |
415 | |
416 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
417 "http3 parse header representation done"); | |
418 | |
419 st->state = sw_start; | |
420 return NGX_DONE; | |
421 } | |
422 | |
423 | |
424 ngx_int_t | |
425 ngx_http_v3_parse_literal(ngx_connection_t *c, ngx_http_v3_parse_literal_t *st, | |
426 u_char ch) | |
427 { | |
8454
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
428 ngx_uint_t n; |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8478
diff
changeset
|
429 ngx_http_v3_srv_conf_t *h3scf; |
8226 | 430 enum { |
431 sw_start = 0, | |
432 sw_value | |
433 }; | |
434 | |
435 switch (st->state) { | |
436 | |
437 case sw_start: | |
438 | |
439 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
440 "http3 parse literal huff:%ui, len:%ui", | |
441 st->huffman, st->length); | |
442 | |
443 n = st->length; | |
444 | |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8478
diff
changeset
|
445 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); |
8454
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
446 |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8478
diff
changeset
|
447 if (n > h3scf->max_field_size) { |
8457
a7f64438aa3c
HTTP/3: downgraded literal size error level to NGX_LOG_INFO.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
448 ngx_log_error(NGX_LOG_INFO, c->log, 0, |
8454
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
449 "client exceeded http3_max_field_size limit"); |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
450 return NGX_HTTP_V3_ERR_EXCESSIVE_LOAD; |
8454
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
451 } |
032cb35ce758
HTTP/3: http3_max_field_size directive to limit string size.
Roman Arutyunyan <arut@nginx.com>
parents:
8295
diff
changeset
|
452 |
8226 | 453 if (st->huffman) { |
454 n = n * 8 / 5; | |
455 st->huffstate = 0; | |
456 } | |
457 | |
458 st->last = ngx_pnalloc(c->pool, n + 1); | |
459 if (st->last == NULL) { | |
460 return NGX_ERROR; | |
461 } | |
462 | |
463 st->value.data = st->last; | |
464 st->state = sw_value; | |
465 | |
466 /* fall through */ | |
467 | |
468 case sw_value: | |
469 | |
470 if (st->huffman) { | |
471 if (ngx_http_v2_huff_decode(&st->huffstate, &ch, 1, &st->last, | |
472 st->length == 1, c->log) | |
473 != NGX_OK) | |
474 { | |
475 return NGX_ERROR; | |
476 } | |
477 | |
478 } else { | |
479 *st->last++ = ch; | |
480 } | |
481 | |
482 if (--st->length) { | |
483 break; | |
484 } | |
485 | |
486 st->value.len = st->last - st->value.data; | |
487 *st->last = '\0'; | |
488 goto done; | |
489 } | |
490 | |
491 return NGX_AGAIN; | |
492 | |
493 done: | |
494 | |
495 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
496 "http3 parse literal done \"%V\"", &st->value); | |
497 | |
498 st->state = sw_start; | |
499 return NGX_DONE; | |
500 } | |
501 | |
502 | |
503 ngx_int_t | |
504 ngx_http_v3_parse_header_ri(ngx_connection_t *c, ngx_http_v3_parse_header_t *st, | |
505 u_char ch) | |
506 { | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
507 ngx_int_t rc; |
8226 | 508 enum { |
509 sw_start = 0, | |
510 sw_index | |
511 }; | |
512 | |
513 switch (st->state) { | |
514 | |
515 case sw_start: | |
516 | |
517 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse header ri"); | |
518 | |
519 st->dynamic = (ch & 0x40) ? 0 : 1; | |
520 st->state = sw_index; | |
521 | |
522 /* fall through */ | |
523 | |
524 case sw_index: | |
525 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
526 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
527 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
528 return rc; |
8226 | 529 } |
530 | |
531 st->index = st->pint.value; | |
532 goto done; | |
533 } | |
534 | |
535 return NGX_AGAIN; | |
536 | |
537 done: | |
538 | |
539 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
540 "http3 parse header ri done %s%ui]", | |
541 st->dynamic ? "dynamic[-" : "static[", st->index); | |
542 | |
543 if (st->dynamic) { | |
544 st->index = st->base - st->index - 1; | |
545 } | |
546 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
547 rc = ngx_http_v3_parse_lookup(c, st->dynamic, st->index, &st->name, |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
548 &st->value); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
549 if (rc != NGX_OK) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
550 return rc; |
8226 | 551 } |
552 | |
553 st->state = sw_start; | |
554 return NGX_DONE; | |
555 } | |
556 | |
557 | |
558 ngx_int_t | |
559 ngx_http_v3_parse_header_lri(ngx_connection_t *c, | |
560 ngx_http_v3_parse_header_t *st, u_char ch) | |
561 { | |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
562 ngx_int_t rc; |
8226 | 563 enum { |
564 sw_start = 0, | |
565 sw_index, | |
566 sw_value_len, | |
567 sw_read_value_len, | |
568 sw_value | |
569 }; | |
570 | |
571 switch (st->state) { | |
572 | |
573 case sw_start: | |
574 | |
575 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse header lri"); | |
576 | |
577 st->dynamic = (ch & 0x10) ? 0 : 1; | |
578 st->state = sw_index; | |
579 | |
580 /* fall through */ | |
581 | |
582 case sw_index: | |
583 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
584 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 4, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
585 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
586 return rc; |
8226 | 587 } |
588 | |
589 st->index = st->pint.value; | |
590 st->state = sw_value_len; | |
591 break; | |
592 | |
593 case sw_value_len: | |
594 | |
595 st->literal.huffman = (ch & 0x80) ? 1 : 0; | |
596 st->state = sw_read_value_len; | |
597 | |
598 /* fall through */ | |
599 | |
600 case sw_read_value_len: | |
601 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
602 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
603 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
604 return rc; |
8226 | 605 } |
606 | |
607 st->literal.length = st->pint.value; | |
608 if (st->literal.length == 0) { | |
609 goto done; | |
610 } | |
611 | |
612 st->state = sw_value; | |
613 break; | |
614 | |
615 case sw_value: | |
616 | |
617 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
618 if (rc != NGX_DONE) { |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
619 return rc; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
620 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
621 |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
622 st->value = st->literal.value; |
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
623 goto done; |
8226 | 624 } |
625 | |
626 return NGX_AGAIN; | |
627 | |
628 done: | |
629 | |
630 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
631 "http3 parse header lri done %s%ui] \"%V\"", | |
632 st->dynamic ? "dynamic[-" : "static[", | |
633 st->index, &st->value); | |
634 | |
635 if (st->dynamic) { | |
636 st->index = st->base - st->index - 1; | |
637 } | |
638 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
639 rc = ngx_http_v3_parse_lookup(c, st->dynamic, st->index, &st->name, NULL); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
640 if (rc != NGX_OK) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
641 return rc; |
8226 | 642 } |
643 | |
644 st->state = sw_start; | |
645 return NGX_DONE; | |
646 } | |
647 | |
648 | |
649 ngx_int_t | |
650 ngx_http_v3_parse_header_l(ngx_connection_t *c, | |
651 ngx_http_v3_parse_header_t *st, u_char ch) | |
652 { | |
653 ngx_int_t rc; | |
654 enum { | |
655 sw_start = 0, | |
656 sw_name_len, | |
657 sw_name, | |
658 sw_value_len, | |
659 sw_read_value_len, | |
660 sw_value | |
661 }; | |
662 | |
663 switch (st->state) { | |
664 | |
665 case sw_start: | |
666 | |
667 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse header l"); | |
668 | |
669 st->literal.huffman = (ch & 0x08) ? 1 : 0; | |
670 st->state = sw_name_len; | |
671 | |
672 /* fall through */ | |
673 | |
674 case sw_name_len: | |
675 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
676 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 3, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
677 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
678 return rc; |
8226 | 679 } |
680 | |
681 st->literal.length = st->pint.value; | |
682 if (st->literal.length == 0) { | |
683 return NGX_ERROR; | |
684 } | |
685 | |
686 st->state = sw_name; | |
687 break; | |
688 | |
689 case sw_name: | |
690 | |
691 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
692 if (rc != NGX_DONE) { |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
693 return rc; |
8226 | 694 } |
695 | |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
696 st->name = st->literal.value; |
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
697 st->state = sw_value_len; |
8226 | 698 break; |
699 | |
700 case sw_value_len: | |
701 | |
702 st->literal.huffman = (ch & 0x80) ? 1 : 0; | |
703 st->state = sw_read_value_len; | |
704 | |
705 /* fall through */ | |
706 | |
707 case sw_read_value_len: | |
708 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
709 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
710 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
711 return rc; |
8226 | 712 } |
713 | |
714 st->literal.length = st->pint.value; | |
715 if (st->literal.length == 0) { | |
716 goto done; | |
717 } | |
718 | |
719 st->state = sw_value; | |
720 break; | |
721 | |
722 case sw_value: | |
723 | |
724 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
725 if (rc != NGX_DONE) { |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
726 return rc; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
727 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
728 |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
729 st->value = st->literal.value; |
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
730 goto done; |
8226 | 731 } |
732 | |
733 return NGX_AGAIN; | |
734 | |
735 done: | |
736 | |
737 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
738 "http3 parse header l done \"%V\" \"%V\"", | |
739 &st->name, &st->value); | |
740 | |
741 st->state = sw_start; | |
742 return NGX_DONE; | |
743 } | |
744 | |
745 | |
746 ngx_int_t | |
747 ngx_http_v3_parse_header_pbi(ngx_connection_t *c, | |
748 ngx_http_v3_parse_header_t *st, u_char ch) | |
749 { | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
750 ngx_int_t rc; |
8226 | 751 enum { |
752 sw_start = 0, | |
753 sw_index | |
754 }; | |
755 | |
756 switch (st->state) { | |
757 | |
758 case sw_start: | |
759 | |
760 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse header pbi"); | |
761 | |
762 st->state = sw_index; | |
763 | |
764 /* fall through */ | |
765 | |
766 case sw_index: | |
767 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
768 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 4, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
769 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
770 return rc; |
8226 | 771 } |
772 | |
773 st->index = st->pint.value; | |
774 goto done; | |
775 } | |
776 | |
777 return NGX_AGAIN; | |
778 | |
779 done: | |
780 | |
781 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
782 "http3 parse header pbi done dynamic[+%ui]", st->index); | |
783 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
784 rc = ngx_http_v3_parse_lookup(c, 1, st->base + st->index, &st->name, |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
785 &st->value); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
786 if (rc != NGX_OK) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
787 return rc; |
8226 | 788 } |
789 | |
790 st->state = sw_start; | |
791 return NGX_DONE; | |
792 } | |
793 | |
794 | |
795 ngx_int_t | |
796 ngx_http_v3_parse_header_lpbi(ngx_connection_t *c, | |
797 ngx_http_v3_parse_header_t *st, u_char ch) | |
798 { | |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
799 ngx_int_t rc; |
8226 | 800 enum { |
801 sw_start = 0, | |
802 sw_index, | |
803 sw_value_len, | |
804 sw_read_value_len, | |
805 sw_value | |
806 }; | |
807 | |
808 switch (st->state) { | |
809 | |
810 case sw_start: | |
811 | |
812 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
813 "http3 parse header lpbi"); | |
814 | |
815 st->state = sw_index; | |
816 | |
817 /* fall through */ | |
818 | |
819 case sw_index: | |
820 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
821 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 3, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
822 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
823 return rc; |
8226 | 824 } |
825 | |
826 st->index = st->pint.value; | |
827 st->state = sw_value_len; | |
828 break; | |
829 | |
830 case sw_value_len: | |
831 | |
832 st->literal.huffman = (ch & 0x80) ? 1 : 0; | |
833 st->state = sw_read_value_len; | |
834 | |
835 /* fall through */ | |
836 | |
837 case sw_read_value_len: | |
838 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
839 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
840 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
841 return rc; |
8226 | 842 } |
843 | |
844 st->literal.length = st->pint.value; | |
845 if (st->literal.length == 0) { | |
846 goto done; | |
847 } | |
848 | |
849 st->state = sw_value; | |
850 break; | |
851 | |
852 case sw_value: | |
853 | |
854 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
855 if (rc != NGX_DONE) { |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
856 return rc; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
857 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
858 |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
859 st->value = st->literal.value; |
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
860 goto done; |
8226 | 861 } |
862 | |
863 return NGX_AGAIN; | |
864 | |
865 done: | |
866 | |
867 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
868 "http3 parse header lpbi done dynamic[+%ui] \"%V\"", | |
869 st->index, &st->value); | |
870 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
871 rc = ngx_http_v3_parse_lookup(c, 1, st->base + st->index, &st->name, NULL); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
872 if (rc != NGX_OK) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
873 return rc; |
8226 | 874 } |
875 | |
876 st->state = sw_start; | |
877 return NGX_DONE; | |
878 } | |
879 | |
880 | |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
881 static ngx_int_t |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
882 ngx_http_v3_parse_lookup(ngx_connection_t *c, ngx_uint_t dynamic, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
883 ngx_uint_t index, ngx_str_t *name, ngx_str_t *value) |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
884 { |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
885 u_char *p; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
886 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
887 if (!dynamic) { |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
888 if (ngx_http_v3_lookup_static(c, index, name, value) != NGX_OK) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
889 return NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
890 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
891 |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
892 return NGX_OK; |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
893 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
894 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
895 if (ngx_http_v3_lookup(c, index, name, value) != NGX_OK) { |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
896 return NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED; |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
897 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
898 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
899 if (name) { |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
900 p = ngx_pnalloc(c->pool, name->len + 1); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
901 if (p == NULL) { |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
902 return NGX_ERROR; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
903 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
904 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
905 ngx_memcpy(p, name->data, name->len); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
906 p[name->len] = '\0'; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
907 name->data = p; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
908 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
909 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
910 if (value) { |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
911 p = ngx_pnalloc(c->pool, value->len + 1); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
912 if (p == NULL) { |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
913 return NGX_ERROR; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
914 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
915 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
916 ngx_memcpy(p, value->data, value->len); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
917 p[value->len] = '\0'; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
918 value->data = p; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
919 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
920 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
921 return NGX_OK; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
922 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
923 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
924 |
8226 | 925 ngx_int_t |
926 ngx_http_v3_parse_control(ngx_connection_t *c, void *data, u_char ch) | |
927 { | |
928 ngx_http_v3_parse_control_t *st = data; | |
929 | |
930 ngx_int_t rc; | |
931 enum { | |
932 sw_start = 0, | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
933 sw_first_type, |
8226 | 934 sw_type, |
935 sw_length, | |
8497 | 936 sw_cancel_push, |
8226 | 937 sw_settings, |
938 sw_max_push_id, | |
939 sw_skip | |
940 }; | |
941 | |
942 switch (st->state) { | |
943 | |
944 case sw_start: | |
945 | |
946 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse control"); | |
947 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
948 st->state = sw_first_type; |
8226 | 949 |
950 /* fall through */ | |
951 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
952 case sw_first_type: |
8226 | 953 case sw_type: |
954 | |
8466
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
955 rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, ch); |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
956 if (rc != NGX_DONE) { |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
957 return rc; |
8226 | 958 } |
959 | |
960 st->type = st->vlint.value; | |
961 | |
962 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
963 "http3 parse frame type:%ui", st->type); | |
964 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
965 if (st->state == sw_first_type |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
966 && st->type != NGX_HTTP_V3_FRAME_SETTINGS) |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
967 { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
968 return NGX_HTTP_V3_ERR_MISSING_SETTINGS; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
969 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
970 |
8226 | 971 st->state = sw_length; |
972 break; | |
973 | |
974 case sw_length: | |
975 | |
8466
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
976 rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, ch); |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
977 if (rc != NGX_DONE) { |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
978 return rc; |
8226 | 979 } |
980 | |
981 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
982 "http3 parse frame len:%uL", st->vlint.value); | |
983 | |
984 st->length = st->vlint.value; | |
985 if (st->length == 0) { | |
986 st->state = sw_type; | |
987 break; | |
988 } | |
989 | |
990 switch (st->type) { | |
991 | |
8497 | 992 case NGX_HTTP_V3_FRAME_CANCEL_PUSH: |
993 st->state = sw_cancel_push; | |
994 break; | |
995 | |
8226 | 996 case NGX_HTTP_V3_FRAME_SETTINGS: |
997 st->state = sw_settings; | |
998 break; | |
999 | |
1000 case NGX_HTTP_V3_FRAME_MAX_PUSH_ID: | |
1001 st->state = sw_max_push_id; | |
1002 break; | |
1003 | |
1004 default: | |
1005 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1006 "http3 parse skip unknown frame"); | |
1007 st->state = sw_skip; | |
1008 } | |
1009 | |
1010 break; | |
1011 | |
8497 | 1012 case sw_cancel_push: |
1013 | |
1014 rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, ch); | |
1015 | |
1016 if (--st->length == 0 && rc == NGX_AGAIN) { | |
1017 return NGX_HTTP_V3_ERR_FRAME_ERROR; | |
1018 } | |
1019 | |
1020 if (rc != NGX_DONE) { | |
1021 return rc; | |
1022 } | |
1023 | |
1024 rc = ngx_http_v3_cancel_push(c, st->vlint.value); | |
1025 if (rc != NGX_OK) { | |
1026 return rc; | |
1027 } | |
1028 | |
1029 st->state = sw_type; | |
1030 break; | |
1031 | |
8226 | 1032 case sw_settings: |
1033 | |
1034 rc = ngx_http_v3_parse_settings(c, &st->settings, ch); | |
1035 | |
8467
e02250b55b17
HTTP/3: simplified handling return codes from parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8466
diff
changeset
|
1036 if (--st->length == 0 && rc == NGX_AGAIN) { |
e02250b55b17
HTTP/3: simplified handling return codes from parse functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8466
diff
changeset
|
1037 return NGX_HTTP_V3_ERR_SETTINGS_ERROR; |
8226 | 1038 } |
1039 | |
1040 if (rc != NGX_DONE) { | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1041 return rc; |
8226 | 1042 } |
1043 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1044 if (st->length == 0) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1045 st->state = sw_type; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1046 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1047 |
8226 | 1048 break; |
1049 | |
1050 case sw_max_push_id: | |
1051 | |
8466
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1052 rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, ch); |
8497 | 1053 |
1054 if (--st->length == 0 && rc == NGX_AGAIN) { | |
1055 return NGX_HTTP_V3_ERR_FRAME_ERROR; | |
1056 } | |
1057 | |
8466
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1058 if (rc != NGX_DONE) { |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1059 return rc; |
8226 | 1060 } |
1061 | |
8497 | 1062 rc = ngx_http_v3_set_max_push_id(c, st->vlint.value); |
1063 if (rc != NGX_OK) { | |
1064 return rc; | |
1065 } | |
8226 | 1066 |
1067 st->state = sw_type; | |
1068 break; | |
1069 | |
1070 case sw_skip: | |
1071 | |
1072 if (--st->length == 0) { | |
1073 st->state = sw_type; | |
1074 } | |
1075 | |
1076 break; | |
1077 } | |
1078 | |
1079 return NGX_AGAIN; | |
1080 } | |
1081 | |
1082 | |
1083 ngx_int_t | |
1084 ngx_http_v3_parse_settings(ngx_connection_t *c, | |
1085 ngx_http_v3_parse_settings_t *st, u_char ch) | |
1086 { | |
8466
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1087 ngx_int_t rc; |
8226 | 1088 enum { |
1089 sw_start = 0, | |
1090 sw_id, | |
1091 sw_value | |
1092 }; | |
1093 | |
1094 switch (st->state) { | |
1095 | |
1096 case sw_start: | |
1097 | |
1098 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse settings"); | |
1099 | |
1100 st->state = sw_id; | |
1101 | |
1102 /* fall through */ | |
1103 | |
1104 case sw_id: | |
1105 | |
8466
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1106 rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, ch); |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1107 if (rc != NGX_DONE) { |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1108 return rc; |
8226 | 1109 } |
1110 | |
1111 st->id = st->vlint.value; | |
1112 st->state = sw_value; | |
1113 break; | |
1114 | |
1115 case sw_value: | |
1116 | |
8466
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1117 rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, ch); |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1118 if (rc != NGX_DONE) { |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1119 return rc; |
8226 | 1120 } |
1121 | |
1122 if (ngx_http_v3_set_param(c, st->id, st->vlint.value) != NGX_OK) { | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1123 return NGX_HTTP_V3_ERR_SETTINGS_ERROR; |
8226 | 1124 } |
1125 | |
1126 goto done; | |
1127 } | |
1128 | |
1129 return NGX_AGAIN; | |
1130 | |
1131 done: | |
1132 | |
1133 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse settings done"); | |
1134 | |
1135 st->state = sw_start; | |
1136 return NGX_DONE; | |
1137 } | |
1138 | |
1139 | |
1140 ngx_int_t | |
1141 ngx_http_v3_parse_encoder(ngx_connection_t *c, void *data, u_char ch) | |
1142 { | |
1143 ngx_http_v3_parse_encoder_t *st = data; | |
1144 | |
1145 ngx_int_t rc; | |
1146 enum { | |
1147 sw_start = 0, | |
1148 sw_inr, | |
1149 sw_iwnr, | |
1150 sw_capacity, | |
1151 sw_duplicate | |
1152 }; | |
1153 | |
1154 if (st->state == sw_start) { | |
1155 | |
1156 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1157 "http3 parse encoder instruction"); | |
1158 | |
1159 if (ch & 0x80) { | |
1160 /* Insert With Name Reference */ | |
1161 | |
1162 st->state = sw_inr; | |
1163 | |
1164 } else if (ch & 0x40) { | |
1165 /* Insert Without Name Reference */ | |
1166 | |
1167 st->state = sw_iwnr; | |
1168 | |
1169 } else if (ch & 0x20) { | |
1170 /* Set Dynamic Table Capacity */ | |
1171 | |
1172 st->state = sw_capacity; | |
1173 | |
1174 } else { | |
1175 /* Duplicate */ | |
1176 | |
1177 st->state = sw_duplicate; | |
1178 } | |
1179 } | |
1180 | |
1181 switch (st->state) { | |
1182 | |
1183 case sw_inr: | |
1184 | |
1185 rc = ngx_http_v3_parse_header_inr(c, &st->header, ch); | |
1186 if (rc != NGX_DONE) { | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1187 return rc; |
8226 | 1188 } |
1189 | |
1190 goto done; | |
1191 | |
1192 case sw_iwnr: | |
1193 | |
1194 rc = ngx_http_v3_parse_header_iwnr(c, &st->header, ch); | |
1195 if (rc != NGX_DONE) { | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1196 return rc; |
8226 | 1197 } |
1198 | |
1199 goto done; | |
1200 | |
1201 case sw_capacity: | |
1202 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1203 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 5, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1204 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1205 return rc; |
8226 | 1206 } |
1207 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1208 rc = ngx_http_v3_set_capacity(c, st->pint.value); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1209 if (rc != NGX_OK) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1210 return rc; |
8226 | 1211 } |
1212 | |
1213 goto done; | |
1214 | |
1215 case sw_duplicate: | |
1216 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1217 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 5, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1218 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1219 return rc; |
8226 | 1220 } |
1221 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1222 rc = ngx_http_v3_duplicate(c, st->pint.value); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1223 if (rc != NGX_OK) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1224 return rc; |
8226 | 1225 } |
1226 | |
1227 goto done; | |
1228 } | |
1229 | |
1230 return NGX_AGAIN; | |
1231 | |
1232 done: | |
1233 | |
1234 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1235 "http3 parse encoder instruction done"); | |
1236 | |
1237 st->state = sw_start; | |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
1238 return NGX_AGAIN; |
8226 | 1239 } |
1240 | |
1241 | |
1242 ngx_int_t | |
1243 ngx_http_v3_parse_header_inr(ngx_connection_t *c, | |
1244 ngx_http_v3_parse_header_t *st, u_char ch) | |
1245 { | |
1246 ngx_int_t rc; | |
1247 enum { | |
1248 sw_start = 0, | |
1249 sw_name_index, | |
1250 sw_value_len, | |
1251 sw_read_value_len, | |
1252 sw_value | |
1253 }; | |
1254 | |
1255 switch (st->state) { | |
1256 | |
1257 case sw_start: | |
1258 | |
1259 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse header inr"); | |
1260 | |
1261 st->dynamic = (ch & 0x40) ? 0 : 1; | |
1262 st->state = sw_name_index; | |
1263 | |
1264 /* fall through */ | |
1265 | |
1266 case sw_name_index: | |
1267 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1268 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1269 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1270 return rc; |
8226 | 1271 } |
1272 | |
1273 st->index = st->pint.value; | |
1274 st->state = sw_value_len; | |
1275 break; | |
1276 | |
1277 case sw_value_len: | |
1278 | |
1279 st->literal.huffman = (ch & 0x80) ? 1 : 0; | |
1280 st->state = sw_read_value_len; | |
1281 | |
1282 /* fall through */ | |
1283 | |
1284 case sw_read_value_len: | |
1285 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1286 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1287 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1288 return rc; |
8226 | 1289 } |
1290 | |
1291 st->literal.length = st->pint.value; | |
1292 if (st->literal.length == 0) { | |
1293 goto done; | |
1294 } | |
1295 | |
1296 st->state = sw_value; | |
1297 break; | |
1298 | |
1299 case sw_value: | |
1300 | |
1301 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
1302 if (rc != NGX_DONE) { |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1303 return rc; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1304 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1305 |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
1306 st->value = st->literal.value; |
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
1307 goto done; |
8226 | 1308 } |
1309 | |
1310 return NGX_AGAIN; | |
1311 | |
1312 done: | |
1313 | |
1314 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1315 "http3 parse header inr done %s[%ui] \"%V\"", | |
1316 st->dynamic ? "dynamic" : "static", | |
1317 st->index, &st->value); | |
1318 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1319 rc = ngx_http_v3_ref_insert(c, st->dynamic, st->index, &st->value); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1320 if (rc != NGX_OK) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1321 return rc; |
8226 | 1322 } |
1323 | |
1324 st->state = sw_start; | |
1325 return NGX_DONE; | |
1326 } | |
1327 | |
1328 | |
1329 ngx_int_t | |
1330 ngx_http_v3_parse_header_iwnr(ngx_connection_t *c, | |
1331 ngx_http_v3_parse_header_t *st, u_char ch) | |
1332 { | |
1333 ngx_int_t rc; | |
1334 enum { | |
1335 sw_start = 0, | |
1336 sw_name_len, | |
1337 sw_name, | |
1338 sw_value_len, | |
1339 sw_read_value_len, | |
1340 sw_value | |
1341 }; | |
1342 | |
1343 switch (st->state) { | |
1344 | |
1345 case sw_start: | |
1346 | |
1347 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1348 "http3 parse header iwnr"); | |
1349 | |
1350 st->literal.huffman = (ch & 0x20) ? 1 : 0; | |
1351 st->state = sw_name_len; | |
1352 | |
1353 /* fall through */ | |
1354 | |
1355 case sw_name_len: | |
1356 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1357 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 5, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1358 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1359 return rc; |
8226 | 1360 } |
1361 | |
1362 st->literal.length = st->pint.value; | |
1363 if (st->literal.length == 0) { | |
1364 return NGX_ERROR; | |
1365 } | |
1366 | |
1367 st->state = sw_name; | |
1368 break; | |
1369 | |
1370 case sw_name: | |
1371 | |
1372 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
1373 if (rc != NGX_DONE) { |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1374 return rc; |
8226 | 1375 } |
1376 | |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
1377 st->name = st->literal.value; |
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
1378 st->state = sw_value_len; |
8226 | 1379 break; |
1380 | |
1381 case sw_value_len: | |
1382 | |
1383 st->literal.huffman = (ch & 0x80) ? 1 : 0; | |
1384 st->state = sw_read_value_len; | |
1385 | |
1386 /* fall through */ | |
1387 | |
1388 case sw_read_value_len: | |
1389 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1390 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1391 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1392 return rc; |
8226 | 1393 } |
1394 | |
1395 st->literal.length = st->pint.value; | |
1396 if (st->literal.length == 0) { | |
1397 goto done; | |
1398 } | |
1399 | |
1400 st->state = sw_value; | |
1401 break; | |
1402 | |
1403 case sw_value: | |
1404 | |
1405 rc = ngx_http_v3_parse_literal(c, &st->literal, ch); | |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
1406 if (rc != NGX_DONE) { |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1407 return rc; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1408 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1409 |
8465
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
1410 st->value = st->literal.value; |
5611bbb852ce
HTTP/3: simplifed handling ngx_http_v3_parse_literal() return code.
Roman Arutyunyan <arut@nginx.com>
parents:
8464
diff
changeset
|
1411 goto done; |
8226 | 1412 } |
1413 | |
1414 return NGX_AGAIN; | |
1415 | |
1416 done: | |
1417 | |
1418 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1419 "http3 parse header iwnr done \"%V\":\"%V\"", | |
1420 &st->name, &st->value); | |
1421 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1422 rc = ngx_http_v3_insert(c, &st->name, &st->value); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1423 if (rc != NGX_OK) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1424 return rc; |
8226 | 1425 } |
1426 | |
1427 st->state = sw_start; | |
1428 return NGX_DONE; | |
1429 } | |
1430 | |
1431 | |
1432 ngx_int_t | |
1433 ngx_http_v3_parse_decoder(ngx_connection_t *c, void *data, u_char ch) | |
1434 { | |
1435 ngx_http_v3_parse_decoder_t *st = data; | |
1436 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1437 ngx_int_t rc; |
8226 | 1438 enum { |
1439 sw_start = 0, | |
1440 sw_ack_header, | |
1441 sw_cancel_stream, | |
1442 sw_inc_insert_count | |
1443 }; | |
1444 | |
1445 if (st->state == sw_start) { | |
1446 | |
1447 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1448 "http3 parse decoder instruction"); | |
1449 | |
1450 if (ch & 0x80) { | |
1451 /* Header Acknowledgement */ | |
1452 | |
1453 st->state = sw_ack_header; | |
1454 | |
1455 } else if (ch & 0x40) { | |
1456 /* Stream Cancellation */ | |
1457 | |
1458 st->state = sw_cancel_stream; | |
1459 | |
1460 } else { | |
1461 /* Insert Count Increment */ | |
1462 | |
1463 st->state = sw_inc_insert_count; | |
1464 } | |
1465 } | |
1466 | |
1467 switch (st->state) { | |
1468 | |
1469 case sw_ack_header: | |
1470 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1471 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1472 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1473 return rc; |
8226 | 1474 } |
1475 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1476 rc = ngx_http_v3_ack_header(c, st->pint.value); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1477 if (rc != NGX_OK) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1478 return rc; |
8226 | 1479 } |
1480 | |
1481 goto done; | |
1482 | |
1483 case sw_cancel_stream: | |
1484 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1485 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1486 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1487 return rc; |
8226 | 1488 } |
1489 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1490 rc = ngx_http_v3_cancel_stream(c, st->pint.value); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1491 if (rc != NGX_OK) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1492 return rc; |
8226 | 1493 } |
1494 | |
1495 goto done; | |
1496 | |
1497 case sw_inc_insert_count: | |
1498 | |
8464
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1499 rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 6, ch); |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1500 if (rc != NGX_DONE) { |
fdb8edc8e496
HTTP/3: limited prefixed integer size by 62 bits.
Roman Arutyunyan <arut@nginx.com>
parents:
8463
diff
changeset
|
1501 return rc; |
8226 | 1502 } |
1503 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1504 rc = ngx_http_v3_inc_insert_count(c, st->pint.value); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1505 if (rc != NGX_OK) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1506 return rc; |
8226 | 1507 } |
1508 | |
1509 goto done; | |
1510 } | |
1511 | |
1512 return NGX_AGAIN; | |
1513 | |
1514 done: | |
1515 | |
1516 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
1517 "http3 parse decoder instruction done"); | |
1518 | |
1519 st->state = sw_start; | |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8455
diff
changeset
|
1520 return NGX_AGAIN; |
8226 | 1521 } |
8295
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1522 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1523 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1524 ngx_int_t |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1525 ngx_http_v3_parse_data(ngx_connection_t *c, ngx_http_v3_parse_data_t *st, |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1526 u_char ch) |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1527 { |
8466
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1528 ngx_int_t rc; |
8295
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1529 enum { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1530 sw_start = 0, |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1531 sw_type, |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1532 sw_length |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1533 }; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1534 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1535 switch (st->state) { |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1536 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1537 case sw_start: |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1538 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1539 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse data"); |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1540 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1541 st->state = sw_type; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1542 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1543 /* fall through */ |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1544 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1545 case sw_type: |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1546 |
8466
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1547 rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, ch); |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1548 if (rc != NGX_DONE) { |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1549 return rc; |
8295
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1550 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1551 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1552 if (st->vlint.value != NGX_HTTP_V3_FRAME_DATA) { |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8457
diff
changeset
|
1553 return NGX_HTTP_V3_ERR_FRAME_UNEXPECTED; |
8295
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1554 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1555 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1556 st->state = sw_length; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1557 break; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1558 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1559 case sw_length: |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1560 |
8466
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1561 rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, ch); |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1562 if (rc != NGX_DONE) { |
4fd709540daf
HTTP/3: put ngx_http_v3_parse_varlen_int() return code in variable.
Roman Arutyunyan <arut@nginx.com>
parents:
8465
diff
changeset
|
1563 return rc; |
8295
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1564 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1565 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1566 st->length = st->vlint.value; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1567 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1568 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1569 "http3 parse data frame len:%ui", st->length); |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1570 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1571 goto done; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1572 } |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1573 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1574 return NGX_AGAIN; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1575 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1576 done: |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1577 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1578 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse data done"); |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1579 |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1580 st->state = sw_start; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1581 return NGX_DONE; |
5649079a41f4
Parsing HTTP/3 request body.
Roman Arutyunyan <arut@nginx.com>
parents:
8227
diff
changeset
|
1582 } |