Mercurial > hg > nginx
annotate src/http/v3/ngx_http_v3_streams.c @ 8824:054f9be0aaf9 quic
HTTP/3: http3_max_uni_streams directive.
The directive limits the number of uni streams client is allowed to create.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Thu, 29 Jul 2021 12:17:56 +0300 |
parents | d80365ca678d |
children | d6e191a583cc |
rev | line source |
---|---|
8215 | 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 | |
13 typedef struct { | |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
14 ngx_http_v3_parse_uni_t parse; |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
15 ngx_int_t index; |
8215 | 16 } ngx_http_v3_uni_stream_t; |
17 | |
18 | |
8497 | 19 typedef struct { |
20 ngx_queue_t queue; | |
21 uint64_t id; | |
22 ngx_connection_t *connection; | |
23 ngx_uint_t *npushing; | |
24 } ngx_http_v3_push_t; | |
25 | |
26 | |
8215 | 27 static void ngx_http_v3_close_uni_stream(ngx_connection_t *c); |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
28 static void ngx_http_v3_uni_read_handler(ngx_event_t *rev); |
8281
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
29 static void ngx_http_v3_dummy_write_handler(ngx_event_t *wev); |
8497 | 30 static void ngx_http_v3_push_cleanup(void *data); |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
31 static ngx_connection_t *ngx_http_v3_get_uni_stream(ngx_connection_t *c, |
8215 | 32 ngx_uint_t type); |
8725
98c4020f1c9a
HTTP/3: keepalive timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
8724
diff
changeset
|
33 |
98c4020f1c9a
HTTP/3: keepalive timeout.
Roman Arutyunyan <arut@nginx.com>
parents:
8724
diff
changeset
|
34 |
8679
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
35 void |
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
36 ngx_http_v3_init_uni_stream(ngx_connection_t *c) |
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
37 { |
8824
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
38 uint64_t n; |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
39 ngx_http_v3_srv_conf_t *h3scf; |
8679
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
40 ngx_http_v3_uni_stream_t *us; |
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
41 |
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
42 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init uni stream"); |
8215 | 43 |
8824
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
44 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
45 |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
46 n = c->quic->id >> 2; |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
47 |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
48 if (n >= h3scf->max_uni_streams) { |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
49 ngx_http_v3_finalize_connection(c, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
50 NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR, |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
51 "reached maximum number of uni streams"); |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
52 ngx_http_close_connection(c); |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
53 return; |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
54 } |
054f9be0aaf9
HTTP/3: http3_max_uni_streams directive.
Roman Arutyunyan <arut@nginx.com>
parents:
8821
diff
changeset
|
55 |
8724
fc64ab301bad
QUIC: connection shutdown.
Roman Arutyunyan <arut@nginx.com>
parents:
8723
diff
changeset
|
56 c->quic->cancelable = 1; |
fc64ab301bad
QUIC: connection shutdown.
Roman Arutyunyan <arut@nginx.com>
parents:
8723
diff
changeset
|
57 |
8215 | 58 us = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_uni_stream_t)); |
59 if (us == NULL) { | |
8679
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
60 ngx_http_close_connection(c); |
e1eb7f4ca9f1
HTTP/3: refactored request parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8630
diff
changeset
|
61 return; |
8215 | 62 } |
63 | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
64 us->index = -1; |
8215 | 65 |
66 c->data = us; | |
67 | |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
68 c->read->handler = ngx_http_v3_uni_read_handler; |
8281
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
69 c->write->handler = ngx_http_v3_dummy_write_handler; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
70 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
71 ngx_http_v3_uni_read_handler(c->read); |
8215 | 72 } |
73 | |
74 | |
75 static void | |
76 ngx_http_v3_close_uni_stream(ngx_connection_t *c) | |
77 { | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
78 ngx_pool_t *pool; |
8770
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
79 ngx_http_v3_session_t *h3c; |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
80 ngx_http_v3_uni_stream_t *us; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
81 |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
82 us = c->data; |
8768
40d710a66aef
HTTP/3: ngx_http_v3_get_session() macro.
Roman Arutyunyan <arut@nginx.com>
parents:
8767
diff
changeset
|
83 h3c = ngx_http_v3_get_session(c); |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
84 |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
85 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 close stream"); |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
86 |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
87 if (us->index >= 0) { |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
88 h3c->known_streams[us->index] = NULL; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
89 } |
8215 | 90 |
91 c->destroyed = 1; | |
92 | |
93 pool = c->pool; | |
94 | |
95 ngx_close_connection(c); | |
96 | |
97 ngx_destroy_pool(pool); | |
98 } | |
99 | |
100 | |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
101 ngx_int_t |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
102 ngx_http_v3_register_uni_stream(ngx_connection_t *c, uint64_t type) |
8215 | 103 { |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
104 ngx_int_t index; |
8770
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
105 ngx_http_v3_session_t *h3c; |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
106 ngx_http_v3_uni_stream_t *us; |
8215 | 107 |
8821
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
108 h3c = ngx_http_v3_get_session(c); |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
109 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
110 switch (type) { |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
111 |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
112 case NGX_HTTP_V3_STREAM_ENCODER: |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
113 |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
114 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
115 "http3 encoder stream"); |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
116 index = NGX_HTTP_V3_STREAM_CLIENT_ENCODER; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
117 break; |
8215 | 118 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
119 case NGX_HTTP_V3_STREAM_DECODER: |
8215 | 120 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
121 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
122 "http3 decoder stream"); |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
123 index = NGX_HTTP_V3_STREAM_CLIENT_DECODER; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
124 break; |
8215 | 125 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
126 case NGX_HTTP_V3_STREAM_CONTROL: |
8215 | 127 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
128 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
129 "http3 control stream"); |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
130 index = NGX_HTTP_V3_STREAM_CLIENT_CONTROL; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
131 |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
132 break; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
133 |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
134 default: |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
135 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
136 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
137 "http3 stream 0x%02xL", type); |
8821
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
138 |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
139 if (h3c->known_streams[NGX_HTTP_V3_STREAM_CLIENT_ENCODER] == NULL |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
140 || h3c->known_streams[NGX_HTTP_V3_STREAM_CLIENT_DECODER] == NULL |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
141 || h3c->known_streams[NGX_HTTP_V3_STREAM_CLIENT_CONTROL] == NULL) |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
142 { |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
143 ngx_log_error(NGX_LOG_INFO, c->log, 0, "missing mandatory stream"); |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
144 return NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR; |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
145 } |
d80365ca678d
HTTP/3: require mandatory uni streams before additional ones.
Roman Arutyunyan <arut@nginx.com>
parents:
8807
diff
changeset
|
146 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
147 index = -1; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
148 } |
8215 | 149 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
150 if (index >= 0) { |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
151 if (h3c->known_streams[index]) { |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
152 ngx_log_error(NGX_LOG_INFO, c->log, 0, "stream exists"); |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
153 return NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR; |
8215 | 154 } |
155 | |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
156 h3c->known_streams[index] = c; |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
157 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
158 us = c->data; |
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
159 us->index = index; |
8215 | 160 } |
161 | |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
162 return NGX_OK; |
8215 | 163 } |
164 | |
165 | |
166 static void | |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
167 ngx_http_v3_uni_read_handler(ngx_event_t *rev) |
8215 | 168 { |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
169 u_char buf[128]; |
8215 | 170 ssize_t n; |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
171 ngx_int_t rc, i; |
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
172 ngx_connection_t *c; |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
173 ngx_http_v3_uni_stream_t *us; |
8215 | 174 |
175 c = rev->data; | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
176 us = c->data; |
8215 | 177 |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
178 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 read handler"); |
8215 | 179 |
180 while (rev->ready) { | |
181 | |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
182 n = c->recv(c, buf, sizeof(buf)); |
8215 | 183 |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
184 if (n == NGX_ERROR) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
185 rc = NGX_HTTP_V3_ERR_INTERNAL_ERROR; |
8215 | 186 goto failed; |
187 } | |
188 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
189 if (n == 0) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
190 if (us->index >= 0) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
191 rc = NGX_HTTP_V3_ERR_CLOSED_CRITICAL_STREAM; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
192 goto failed; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
193 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
194 |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
195 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 read eof"); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
196 ngx_http_v3_close_uni_stream(c); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
197 return; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
198 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
199 |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
200 if (n == NGX_AGAIN) { |
8215 | 201 break; |
202 } | |
203 | |
8226
268f4389130d
Refactored HTTP/3 parser.
Roman Arutyunyan <arut@nginx.com>
parents:
8215
diff
changeset
|
204 for (i = 0; i < n; i++) { |
8215 | 205 |
8772
345370fdd32d
HTTP/3: moved parsing uni stream type to ngx_http_v3_parse.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8771
diff
changeset
|
206 rc = ngx_http_v3_parse_uni(c, &us->parse, buf[i]); |
8215 | 207 |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
208 if (rc == NGX_DONE) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
209 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
210 "http3 read done"); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
211 ngx_http_v3_close_uni_stream(c); |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
212 return; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
213 } |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
214 |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
215 if (rc > 0) { |
8215 | 216 goto failed; |
217 } | |
218 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
219 if (rc != NGX_AGAIN) { |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
220 rc = NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR; |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
221 goto failed; |
8215 | 222 } |
223 } | |
224 } | |
225 | |
226 if (ngx_handle_read_event(rev, 0) != NGX_OK) { | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
227 rc = NGX_HTTP_V3_ERR_INTERNAL_ERROR; |
8215 | 228 goto failed; |
229 } | |
230 | |
231 return; | |
232 | |
233 failed: | |
234 | |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
235 ngx_http_v3_finalize_connection(c, rc, "stream error"); |
8215 | 236 ngx_http_v3_close_uni_stream(c); |
237 } | |
238 | |
239 | |
8281
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
240 static void |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
241 ngx_http_v3_dummy_write_handler(ngx_event_t *wev) |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
242 { |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
243 ngx_connection_t *c; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
244 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
245 c = wev->data; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
246 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
247 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 dummy write handler"); |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
248 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
249 if (ngx_handle_write_event(wev, 0) != NGX_OK) { |
8460
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
250 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR, |
72f9ff4e0a88
HTTP/3: close QUIC connection with HTTP/QPACK errors when needed.
Roman Arutyunyan <arut@nginx.com>
parents:
8456
diff
changeset
|
251 NULL); |
8281
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
252 ngx_http_v3_close_uni_stream(c); |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
253 } |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
254 } |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
255 |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
256 |
8215 | 257 /* XXX async & buffered stream writes */ |
258 | |
8497 | 259 ngx_connection_t * |
260 ngx_http_v3_create_push_stream(ngx_connection_t *c, uint64_t push_id) | |
261 { | |
8770
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
262 u_char *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 2]; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
263 size_t n; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
264 ngx_connection_t *sc; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
265 ngx_pool_cleanup_t *cln; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
266 ngx_http_v3_push_t *push; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
267 ngx_http_v3_session_t *h3c; |
8497 | 268 |
269 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
270 "http3 create push stream id:%uL", push_id); | |
271 | |
272 sc = ngx_quic_open_stream(c, 0); | |
273 if (sc == NULL) { | |
274 return NULL; | |
275 } | |
276 | |
277 p = buf; | |
278 p = (u_char *) ngx_http_v3_encode_varlen_int(p, NGX_HTTP_V3_STREAM_PUSH); | |
279 p = (u_char *) ngx_http_v3_encode_varlen_int(p, push_id); | |
280 n = p - buf; | |
281 | |
282 if (sc->send(sc, buf, n) != (ssize_t) n) { | |
283 goto failed; | |
284 } | |
285 | |
286 cln = ngx_pool_cleanup_add(sc->pool, sizeof(ngx_http_v3_push_t)); | |
287 if (cln == NULL) { | |
288 goto failed; | |
289 } | |
290 | |
8768
40d710a66aef
HTTP/3: ngx_http_v3_get_session() macro.
Roman Arutyunyan <arut@nginx.com>
parents:
8767
diff
changeset
|
291 h3c = ngx_http_v3_get_session(c); |
8497 | 292 h3c->npushing++; |
293 | |
294 cln->handler = ngx_http_v3_push_cleanup; | |
295 | |
296 push = cln->data; | |
297 push->id = push_id; | |
298 push->connection = sc; | |
299 push->npushing = &h3c->npushing; | |
300 | |
301 ngx_queue_insert_tail(&h3c->pushing, &push->queue); | |
302 | |
303 return sc; | |
304 | |
305 failed: | |
306 | |
307 ngx_http_v3_close_uni_stream(sc); | |
308 | |
309 return NULL; | |
310 } | |
311 | |
312 | |
313 static void | |
314 ngx_http_v3_push_cleanup(void *data) | |
315 { | |
316 ngx_http_v3_push_t *push = data; | |
317 | |
318 ngx_queue_remove(&push->queue); | |
319 (*push->npushing)--; | |
320 } | |
321 | |
322 | |
8215 | 323 static ngx_connection_t * |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
324 ngx_http_v3_get_uni_stream(ngx_connection_t *c, ngx_uint_t type) |
8215 | 325 { |
326 u_char buf[NGX_HTTP_V3_VARLEN_INT_LEN]; | |
327 size_t n; | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
328 ngx_int_t index; |
8215 | 329 ngx_connection_t *sc; |
8770
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
330 ngx_http_v3_session_t *h3c; |
8215 | 331 ngx_http_v3_uni_stream_t *us; |
332 | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
333 switch (type) { |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
334 case NGX_HTTP_V3_STREAM_ENCODER: |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
335 index = NGX_HTTP_V3_STREAM_SERVER_ENCODER; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
336 break; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
337 case NGX_HTTP_V3_STREAM_DECODER: |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
338 index = NGX_HTTP_V3_STREAM_SERVER_DECODER; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
339 break; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
340 case NGX_HTTP_V3_STREAM_CONTROL: |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
341 index = NGX_HTTP_V3_STREAM_SERVER_CONTROL; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
342 break; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
343 default: |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
344 index = -1; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
345 } |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
346 |
8768
40d710a66aef
HTTP/3: ngx_http_v3_get_session() macro.
Roman Arutyunyan <arut@nginx.com>
parents:
8767
diff
changeset
|
347 h3c = ngx_http_v3_get_session(c); |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
348 |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
349 if (index >= 0) { |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
350 if (h3c->known_streams[index]) { |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
351 return h3c->known_streams[index]; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
352 } |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
353 } |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
354 |
8495
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8492
diff
changeset
|
355 sc = ngx_quic_open_stream(c, 0); |
8215 | 356 if (sc == NULL) { |
357 return NULL; | |
358 } | |
359 | |
8724
fc64ab301bad
QUIC: connection shutdown.
Roman Arutyunyan <arut@nginx.com>
parents:
8723
diff
changeset
|
360 sc->quic->cancelable = 1; |
fc64ab301bad
QUIC: connection shutdown.
Roman Arutyunyan <arut@nginx.com>
parents:
8723
diff
changeset
|
361 |
8215 | 362 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
363 "http3 create uni stream, type:%ui", type); | |
364 | |
365 us = ngx_pcalloc(sc->pool, sizeof(ngx_http_v3_uni_stream_t)); | |
366 if (us == NULL) { | |
367 goto failed; | |
368 } | |
369 | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
370 us->index = index; |
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
371 |
8215 | 372 sc->data = us; |
373 | |
8281
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
374 sc->read->handler = ngx_http_v3_uni_read_handler; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
375 sc->write->handler = ngx_http_v3_dummy_write_handler; |
618a65de08b3
When closing a QUIC connection, wait for all streams to finish.
Roman Arutyunyan <arut@nginx.com>
parents:
8228
diff
changeset
|
376 |
8403
c101438c69a4
HTTP/3: prevent array access by negative index for unknown streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8362
diff
changeset
|
377 if (index >= 0) { |
c101438c69a4
HTTP/3: prevent array access by negative index for unknown streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8362
diff
changeset
|
378 h3c->known_streams[index] = sc; |
c101438c69a4
HTTP/3: prevent array access by negative index for unknown streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8362
diff
changeset
|
379 } |
8215 | 380 |
381 n = (u_char *) ngx_http_v3_encode_varlen_int(buf, type) - buf; | |
382 | |
383 if (sc->send(sc, buf, n) != (ssize_t) n) { | |
384 goto failed; | |
385 } | |
386 | |
387 return sc; | |
388 | |
389 failed: | |
390 | |
391 ngx_http_v3_close_uni_stream(sc); | |
392 | |
393 return NULL; | |
394 } | |
395 | |
396 | |
8774
f4d3f5d93a82
HTTP/3: moved session initialization to a separate file.
Roman Arutyunyan <arut@nginx.com>
parents:
8772
diff
changeset
|
397 ngx_int_t |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
398 ngx_http_v3_send_settings(ngx_connection_t *c) |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
399 { |
8769
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8768
diff
changeset
|
400 u_char *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 6]; |
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8768
diff
changeset
|
401 size_t n; |
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8768
diff
changeset
|
402 ngx_connection_t *cc; |
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8768
diff
changeset
|
403 ngx_http_v3_srv_conf_t *h3scf; |
8495
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8492
diff
changeset
|
404 |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
405 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send settings"); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
406 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
407 cc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_CONTROL); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
408 if (cc == NULL) { |
8495
455a8536eaa7
QUIC: limited the number of server-initiated streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8492
diff
changeset
|
409 return NGX_DECLINED; |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
410 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
411 |
8769
9ec3e71f8a61
HTTP/3: reference h3c directly from ngx_http_connection_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8768
diff
changeset
|
412 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
413 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
414 n = ngx_http_v3_encode_varlen_int(NULL, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
415 NGX_HTTP_V3_PARAM_MAX_TABLE_CAPACITY); |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
416 n += ngx_http_v3_encode_varlen_int(NULL, h3scf->max_table_capacity); |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
417 n += ngx_http_v3_encode_varlen_int(NULL, NGX_HTTP_V3_PARAM_BLOCKED_STREAMS); |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
418 n += ngx_http_v3_encode_varlen_int(NULL, h3scf->max_blocked_streams); |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
419 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
420 p = (u_char *) ngx_http_v3_encode_varlen_int(buf, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
421 NGX_HTTP_V3_FRAME_SETTINGS); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
422 p = (u_char *) ngx_http_v3_encode_varlen_int(p, n); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
423 p = (u_char *) ngx_http_v3_encode_varlen_int(p, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
424 NGX_HTTP_V3_PARAM_MAX_TABLE_CAPACITY); |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
425 p = (u_char *) ngx_http_v3_encode_varlen_int(p, h3scf->max_table_capacity); |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
426 p = (u_char *) ngx_http_v3_encode_varlen_int(p, |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
427 NGX_HTTP_V3_PARAM_BLOCKED_STREAMS); |
8492
65c1fc5fae15
HTTP/3: renamed server configuration variables from v3cf to h3scf.
Roman Arutyunyan <arut@nginx.com>
parents:
8481
diff
changeset
|
428 p = (u_char *) ngx_http_v3_encode_varlen_int(p, h3scf->max_blocked_streams); |
8456
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
429 n = p - buf; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
430 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
431 if (cc->send(cc, buf, n) != (ssize_t) n) { |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
432 goto failed; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
433 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
434 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
435 return NGX_OK; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
436 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
437 failed: |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
438 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
439 ngx_http_v3_close_uni_stream(cc); |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
440 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
441 return NGX_ERROR; |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
442 } |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
443 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
444 |
c9538aef3211
HTTP/3: refactored dynamic table implementation.
Roman Arutyunyan <arut@nginx.com>
parents:
8403
diff
changeset
|
445 ngx_int_t |
8723
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
446 ngx_http_v3_send_goaway(ngx_connection_t *c, uint64_t id) |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
447 { |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
448 u_char *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 3]; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
449 size_t n; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
450 ngx_connection_t *cc; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
451 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
452 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send goaway %uL", id); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
453 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
454 cc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_CONTROL); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
455 if (cc == NULL) { |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
456 return NGX_DECLINED; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
457 } |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
458 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
459 n = ngx_http_v3_encode_varlen_int(NULL, id); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
460 p = (u_char *) ngx_http_v3_encode_varlen_int(buf, NGX_HTTP_V3_FRAME_GOAWAY); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
461 p = (u_char *) ngx_http_v3_encode_varlen_int(p, n); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
462 p = (u_char *) ngx_http_v3_encode_varlen_int(p, id); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
463 n = p - buf; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
464 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
465 if (cc->send(cc, buf, n) != (ssize_t) n) { |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
466 goto failed; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
467 } |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
468 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
469 return NGX_OK; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
470 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
471 failed: |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
472 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
473 ngx_http_v3_close_uni_stream(cc); |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
474 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
475 return NGX_ERROR; |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
476 } |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
477 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
478 |
265062a99043
HTTP/3: send GOAWAY when last request is accepted.
Roman Arutyunyan <arut@nginx.com>
parents:
8719
diff
changeset
|
479 ngx_int_t |
8771
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8770
diff
changeset
|
480 ngx_http_v3_send_ref_insert(ngx_connection_t *c, ngx_uint_t dynamic, |
8215 | 481 ngx_uint_t index, ngx_str_t *value) |
482 { | |
483 u_char *p, buf[NGX_HTTP_V3_PREFIX_INT_LEN * 2]; | |
484 size_t n; | |
485 ngx_connection_t *ec; | |
486 | |
487 ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
488 "http3 client ref insert, %s[%ui] \"%V\"", | |
489 dynamic ? "dynamic" : "static", index, value); | |
490 | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
491 ec = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_ENCODER); |
8215 | 492 if (ec == NULL) { |
493 return NGX_ERROR; | |
494 } | |
495 | |
496 p = buf; | |
497 | |
498 *p = (dynamic ? 0x80 : 0xc0); | |
499 p = (u_char *) ngx_http_v3_encode_prefix_int(p, index, 6); | |
500 | |
501 /* XXX option for huffman? */ | |
502 *p = 0; | |
503 p = (u_char *) ngx_http_v3_encode_prefix_int(p, value->len, 7); | |
504 | |
505 n = p - buf; | |
506 | |
507 if (ec->send(ec, buf, n) != (ssize_t) n) { | |
508 goto failed; | |
509 } | |
510 | |
511 if (ec->send(ec, value->data, value->len) != (ssize_t) value->len) { | |
512 goto failed; | |
513 } | |
514 | |
515 return NGX_OK; | |
516 | |
517 failed: | |
518 | |
519 ngx_http_v3_close_uni_stream(ec); | |
520 | |
521 return NGX_ERROR; | |
522 } | |
523 | |
524 | |
525 ngx_int_t | |
8771
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8770
diff
changeset
|
526 ngx_http_v3_send_insert(ngx_connection_t *c, ngx_str_t *name, ngx_str_t *value) |
8215 | 527 { |
528 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; | |
529 size_t n; | |
530 ngx_connection_t *ec; | |
531 | |
532 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
533 "http3 client insert \"%V\":\"%V\"", name, value); | |
534 | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
535 ec = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_ENCODER); |
8215 | 536 if (ec == NULL) { |
537 return NGX_ERROR; | |
538 } | |
539 | |
540 /* XXX option for huffman? */ | |
541 buf[0] = 0x40; | |
542 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, name->len, 5) - buf; | |
543 | |
544 if (ec->send(ec, buf, n) != (ssize_t) n) { | |
545 goto failed; | |
546 } | |
547 | |
548 if (ec->send(ec, name->data, name->len) != (ssize_t) name->len) { | |
549 goto failed; | |
550 } | |
551 | |
552 /* XXX option for huffman? */ | |
553 buf[0] = 0; | |
554 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, value->len, 7) - buf; | |
555 | |
556 if (ec->send(ec, buf, n) != (ssize_t) n) { | |
557 goto failed; | |
558 } | |
559 | |
560 if (ec->send(ec, value->data, value->len) != (ssize_t) value->len) { | |
561 goto failed; | |
562 } | |
563 | |
564 return NGX_OK; | |
565 | |
566 failed: | |
567 | |
568 ngx_http_v3_close_uni_stream(ec); | |
569 | |
570 return NGX_ERROR; | |
571 } | |
572 | |
573 | |
574 ngx_int_t | |
8771
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8770
diff
changeset
|
575 ngx_http_v3_send_set_capacity(ngx_connection_t *c, ngx_uint_t capacity) |
8215 | 576 { |
577 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; | |
578 size_t n; | |
579 ngx_connection_t *ec; | |
580 | |
581 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
582 "http3 client set capacity %ui", capacity); | |
583 | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
584 ec = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_ENCODER); |
8215 | 585 if (ec == NULL) { |
586 return NGX_ERROR; | |
587 } | |
588 | |
589 buf[0] = 0x20; | |
590 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, capacity, 5) - buf; | |
591 | |
592 if (ec->send(ec, buf, n) != (ssize_t) n) { | |
593 ngx_http_v3_close_uni_stream(ec); | |
594 return NGX_ERROR; | |
595 } | |
596 | |
597 return NGX_OK; | |
598 } | |
599 | |
600 | |
601 ngx_int_t | |
8771
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8770
diff
changeset
|
602 ngx_http_v3_send_duplicate(ngx_connection_t *c, ngx_uint_t index) |
8215 | 603 { |
604 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; | |
605 size_t n; | |
606 ngx_connection_t *ec; | |
607 | |
608 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
609 "http3 client duplicate %ui", index); | |
610 | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
611 ec = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_ENCODER); |
8215 | 612 if (ec == NULL) { |
613 return NGX_ERROR; | |
614 } | |
615 | |
616 buf[0] = 0; | |
617 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, index, 5) - buf; | |
618 | |
619 if (ec->send(ec, buf, n) != (ssize_t) n) { | |
620 ngx_http_v3_close_uni_stream(ec); | |
621 return NGX_ERROR; | |
622 } | |
623 | |
624 return NGX_OK; | |
625 } | |
626 | |
627 | |
628 ngx_int_t | |
8807
0ac25efb2da3
HTTP/3: quic-qpack term updates.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8796
diff
changeset
|
629 ngx_http_v3_send_ack_section(ngx_connection_t *c, ngx_uint_t stream_id) |
8215 | 630 { |
631 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; | |
632 size_t n; | |
633 ngx_connection_t *dc; | |
634 | |
635 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
8807
0ac25efb2da3
HTTP/3: quic-qpack term updates.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8796
diff
changeset
|
636 "http3 client ack section %ui", stream_id); |
8215 | 637 |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
638 dc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_DECODER); |
8215 | 639 if (dc == NULL) { |
640 return NGX_ERROR; | |
641 } | |
642 | |
643 buf[0] = 0x80; | |
644 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, stream_id, 7) - buf; | |
645 | |
646 if (dc->send(dc, buf, n) != (ssize_t) n) { | |
647 ngx_http_v3_close_uni_stream(dc); | |
648 return NGX_ERROR; | |
649 } | |
650 | |
651 return NGX_OK; | |
652 } | |
653 | |
654 | |
655 ngx_int_t | |
8771
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8770
diff
changeset
|
656 ngx_http_v3_send_cancel_stream(ngx_connection_t *c, ngx_uint_t stream_id) |
8215 | 657 { |
658 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; | |
659 size_t n; | |
660 ngx_connection_t *dc; | |
661 | |
662 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
663 "http3 client cancel stream %ui", stream_id); | |
664 | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
665 dc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_DECODER); |
8215 | 666 if (dc == NULL) { |
667 return NGX_ERROR; | |
668 } | |
669 | |
670 buf[0] = 0x40; | |
671 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, stream_id, 6) - buf; | |
672 | |
673 if (dc->send(dc, buf, n) != (ssize_t) n) { | |
674 ngx_http_v3_close_uni_stream(dc); | |
675 return NGX_ERROR; | |
676 } | |
677 | |
678 return NGX_OK; | |
679 } | |
680 | |
681 | |
682 ngx_int_t | |
8771
0981329169ea
HTTP/3: renamed ngx_http_v3_client_XXX() functions.
Roman Arutyunyan <arut@nginx.com>
parents:
8770
diff
changeset
|
683 ngx_http_v3_send_inc_insert_count(ngx_connection_t *c, ngx_uint_t inc) |
8215 | 684 { |
685 u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN]; | |
686 size_t n; | |
687 ngx_connection_t *dc; | |
688 | |
689 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
690 "http3 client increment insert count %ui", inc); | |
691 | |
8283
dadbc66e9fca
Simplifed handling HTTP/3 streams.
Roman Arutyunyan <arut@nginx.com>
parents:
8281
diff
changeset
|
692 dc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_DECODER); |
8215 | 693 if (dc == NULL) { |
694 return NGX_ERROR; | |
695 } | |
696 | |
697 buf[0] = 0; | |
698 n = (u_char *) ngx_http_v3_encode_prefix_int(buf, inc, 6) - buf; | |
699 | |
700 if (dc->send(dc, buf, n) != (ssize_t) n) { | |
701 ngx_http_v3_close_uni_stream(dc); | |
702 return NGX_ERROR; | |
703 } | |
704 | |
705 return NGX_OK; | |
706 } | |
8497 | 707 |
708 | |
709 ngx_int_t | |
710 ngx_http_v3_set_max_push_id(ngx_connection_t *c, uint64_t max_push_id) | |
711 { | |
8770
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
712 ngx_http_v3_session_t *h3c; |
8497 | 713 |
8768
40d710a66aef
HTTP/3: ngx_http_v3_get_session() macro.
Roman Arutyunyan <arut@nginx.com>
parents:
8767
diff
changeset
|
714 h3c = ngx_http_v3_get_session(c); |
8497 | 715 |
716 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
717 "http3 MAX_PUSH_ID:%uL", max_push_id); | |
718 | |
8719
5cb5b568282b
HTTP/3: do not push until a MAX_PUSH_ID frame is received.
Sergey Kandaurov <pluknet@nginx.com>
parents:
8679
diff
changeset
|
719 if (h3c->max_push_id != (uint64_t) -1 && max_push_id < h3c->max_push_id) { |
8497 | 720 return NGX_HTTP_V3_ERR_ID_ERROR; |
721 } | |
722 | |
723 h3c->max_push_id = max_push_id; | |
724 | |
725 return NGX_OK; | |
726 } | |
727 | |
728 | |
729 ngx_int_t | |
8796
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
730 ngx_http_v3_goaway(ngx_connection_t *c, uint64_t push_id) |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
731 { |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
732 ngx_http_v3_session_t *h3c; |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
733 |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
734 h3c = ngx_http_v3_get_session(c); |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
735 |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
736 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 GOAWAY:%uL", push_id); |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
737 |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
738 h3c->goaway_push_id = push_id; |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
739 |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
740 return NGX_OK; |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
741 } |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
742 |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
743 |
1fec68e322d0
HTTP/3: client GOAWAY support.
Roman Arutyunyan <arut@nginx.com>
parents:
8774
diff
changeset
|
744 ngx_int_t |
8497 | 745 ngx_http_v3_cancel_push(ngx_connection_t *c, uint64_t push_id) |
746 { | |
8770
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
747 ngx_queue_t *q; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
748 ngx_http_request_t *r; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
749 ngx_http_v3_push_t *push; |
67f0eb150047
HTTP/3: renamed ngx_http_v3_connection_t to ngx_http_v3_session_t.
Roman Arutyunyan <arut@nginx.com>
parents:
8769
diff
changeset
|
750 ngx_http_v3_session_t *h3c; |
8497 | 751 |
8768
40d710a66aef
HTTP/3: ngx_http_v3_get_session() macro.
Roman Arutyunyan <arut@nginx.com>
parents:
8767
diff
changeset
|
752 h3c = ngx_http_v3_get_session(c); |
8497 | 753 |
754 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, | |
755 "http3 CANCEL_PUSH:%uL", push_id); | |
756 | |
757 if (push_id >= h3c->next_push_id) { | |
758 return NGX_HTTP_V3_ERR_ID_ERROR; | |
759 } | |
760 | |
761 for (q = ngx_queue_head(&h3c->pushing); | |
762 q != ngx_queue_sentinel(&h3c->pushing); | |
763 q = ngx_queue_next(&h3c->pushing)) | |
764 { | |
765 push = (ngx_http_v3_push_t *) q; | |
766 | |
767 if (push->id != push_id) { | |
768 continue; | |
769 } | |
770 | |
771 r = push->connection->data; | |
772 | |
773 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | |
774 "http3 cancel push"); | |
775 | |
776 ngx_http_finalize_request(r, NGX_HTTP_CLOSE); | |
777 | |
778 break; | |
779 } | |
780 | |
781 return NGX_OK; | |
782 } | |
8767
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
783 |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
784 |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
785 ngx_int_t |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
786 ngx_http_v3_cancel_stream(ngx_connection_t *c, ngx_uint_t stream_id) |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
787 { |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
788 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
789 "http3 cancel stream %ui", stream_id); |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
790 |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
791 /* we do not use dynamic tables */ |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
792 |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
793 return NGX_OK; |
33ec97749b5f
HTTP/3: moved Stream Cancellation stub to ngx_http_v3_streams.c.
Roman Arutyunyan <arut@nginx.com>
parents:
8725
diff
changeset
|
794 } |