comparison src/http/v3/ngx_http_v3_request.c @ 8986:6546c2ae1c7b quic

HTTP/3: unified hq code with regular HTTP/3 code. The change removes hq-specific request handler. Now hq requests are handled by the HTTP/3 request handler.
author Roman Arutyunyan <arut@nginx.com>
date Wed, 19 Oct 2022 17:45:30 +0400
parents 210ad79a8853
children 1192923be0aa
comparison
equal deleted inserted replaced
8985:740d7d6e8ff0 8986:6546c2ae1c7b
8 #include <ngx_config.h> 8 #include <ngx_config.h>
9 #include <ngx_core.h> 9 #include <ngx_core.h>
10 #include <ngx_http.h> 10 #include <ngx_http.h>
11 11
12 12
13 #if (NGX_HTTP_V3_HQ)
14 static void ngx_http_v3_init_hq_stream(ngx_connection_t *c);
15 #endif
16 static void ngx_http_v3_init_request_stream(ngx_connection_t *c); 13 static void ngx_http_v3_init_request_stream(ngx_connection_t *c);
17 static void ngx_http_v3_wait_request_handler(ngx_event_t *rev); 14 static void ngx_http_v3_wait_request_handler(ngx_event_t *rev);
18 static void ngx_http_v3_cleanup_request(void *data); 15 static void ngx_http_v3_cleanup_request(void *data);
19 static void ngx_http_v3_process_request(ngx_event_t *rev); 16 static void ngx_http_v3_process_request(ngx_event_t *rev);
20 static ngx_int_t ngx_http_v3_process_header(ngx_http_request_t *r, 17 static ngx_int_t ngx_http_v3_process_header(ngx_http_request_t *r,
87 hc->conf_ctx = phc->conf_ctx; 84 hc->conf_ctx = phc->conf_ctx;
88 85
89 ngx_set_connection_log(c, clcf->error_log); 86 ngx_set_connection_log(c, clcf->error_log);
90 } 87 }
91 88
92 #if (NGX_HTTP_V3_HQ)
93 if (h3scf->hq) {
94 ngx_http_v3_init_hq_stream(c);
95 return;
96 }
97 #endif
98
99 if (ngx_http_v3_init_session(c) != NGX_OK) { 89 if (ngx_http_v3_init_session(c) != NGX_OK) {
100 ngx_http_close_connection(c); 90 ngx_http_close_connection(c);
101 return; 91 return;
102 } 92 }
103 93
108 ngx_http_v3_init_request_stream(c); 98 ngx_http_v3_init_request_stream(c);
109 } 99 }
110 } 100 }
111 101
112 102
113 #if (NGX_HTTP_V3_HQ)
114
115 static void 103 static void
116 ngx_http_v3_init_hq_stream(ngx_connection_t *c) 104 ngx_http_v3_init_request_stream(ngx_connection_t *c)
117 { 105 {
118 uint64_t n; 106 uint64_t n;
119 ngx_event_t *rev; 107 ngx_event_t *rev;
120 ngx_http_connection_t *hc; 108 ngx_connection_t *pc;
121 ngx_http_core_loc_conf_t *clcf;
122 ngx_http_core_srv_conf_t *cscf;
123
124 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init hq stream");
125
126 #if (NGX_STAT_STUB)
127 (void) ngx_atomic_fetch_add(ngx_stat_active, 1);
128 #endif
129
130 hc = c->data;
131
132 /* Use HTTP/3 General Protocol Error Code 0x101 for finalization */
133
134 if (c->quic->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) {
135 ngx_quic_finalize_connection(c->quic->parent,
136 NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR,
137 "unexpected uni stream");
138 ngx_http_close_connection(c);
139 return;
140 }
141
142 clcf = ngx_http_get_module_loc_conf(hc->conf_ctx, ngx_http_core_module);
143
144 n = c->quic->id >> 2;
145
146 if (n >= clcf->keepalive_requests) {
147 ngx_quic_finalize_connection(c->quic->parent,
148 NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR,
149 "reached maximum number of requests");
150 ngx_http_close_connection(c);
151 return;
152 }
153
154 if (ngx_current_msec - c->quic->parent->start_time
155 > clcf->keepalive_time)
156 {
157 ngx_quic_finalize_connection(c->quic->parent,
158 NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR,
159 "reached maximum time for requests");
160 ngx_http_close_connection(c);
161 return;
162 }
163
164 rev = c->read;
165
166 if (rev->ready) {
167 rev->handler(rev);
168 return;
169 }
170
171 cscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_core_module);
172
173 ngx_add_timer(rev, cscf->client_header_timeout);
174 ngx_reusable_connection(c, 1);
175
176 if (ngx_handle_read_event(rev, 0) != NGX_OK) {
177 ngx_http_close_connection(c);
178 return;
179 }
180 }
181
182 #endif
183
184
185 static void
186 ngx_http_v3_init_request_stream(ngx_connection_t *c)
187 {
188 uint64_t n;
189 ngx_event_t *rev;
190 ngx_http_connection_t *hc; 109 ngx_http_connection_t *hc;
191 ngx_http_v3_session_t *h3c; 110 ngx_http_v3_session_t *h3c;
192 ngx_http_core_loc_conf_t *clcf; 111 ngx_http_core_loc_conf_t *clcf;
193 ngx_http_core_srv_conf_t *cscf; 112 ngx_http_core_srv_conf_t *cscf;
194 113
217 c->close = 1; 136 c->close = 1;
218 ngx_http_close_connection(c); 137 ngx_http_close_connection(c);
219 return; 138 return;
220 } 139 }
221 140
141 pc = c->quic->parent;
142
222 if (n + 1 == clcf->keepalive_requests 143 if (n + 1 == clcf->keepalive_requests
223 || ngx_current_msec - c->quic->parent->start_time 144 || ngx_current_msec - pc->start_time > clcf->keepalive_time)
224 > clcf->keepalive_time)
225 { 145 {
226 h3c->goaway = 1; 146 h3c->goaway = 1;
227 147
228 if (ngx_http_v3_send_goaway(c, (n + 1) << 2) != NGX_OK) { 148 #if (NGX_HTTP_V3_HQ)
229 ngx_http_close_connection(c); 149 if (!h3c->hq)
230 return; 150 #endif
151 {
152 if (ngx_http_v3_send_goaway(c, (n + 1) << 2) != NGX_OK) {
153 ngx_http_close_connection(c);
154 return;
155 }
231 } 156 }
232 157
233 ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR, 158 ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
234 "reached maximum number of requests"); 159 "reached maximum number of requests");
235 } 160 }
236 161
237 rev = c->read; 162 rev = c->read;
238 rev->handler = ngx_http_v3_wait_request_handler; 163
239 c->write->handler = ngx_http_empty_handler; 164 #if (NGX_HTTP_V3_HQ)
165 if (!h3c->hq)
166 #endif
167 {
168 rev->handler = ngx_http_v3_wait_request_handler;
169 c->write->handler = ngx_http_empty_handler;
170 }
240 171
241 if (rev->ready) { 172 if (rev->ready) {
242 rev->handler(rev); 173 rev->handler(rev);
243 return; 174 return;
244 } 175 }
262 ssize_t n; 193 ssize_t n;
263 ngx_buf_t *b; 194 ngx_buf_t *b;
264 ngx_connection_t *c; 195 ngx_connection_t *c;
265 ngx_pool_cleanup_t *cln; 196 ngx_pool_cleanup_t *cln;
266 ngx_http_request_t *r; 197 ngx_http_request_t *r;
198 ngx_http_v3_session_t *h3c;
267 ngx_http_connection_t *hc; 199 ngx_http_connection_t *hc;
268 ngx_http_v3_session_t *h3c;
269 ngx_http_core_srv_conf_t *cscf; 200 ngx_http_core_srv_conf_t *cscf;
270 201
271 c = rev->data; 202 c = rev->data;
272 203
273 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 wait request handler"); 204 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 wait request handler");
402 { 333 {
403 ngx_http_v3_srv_conf_t *h3scf; 334 ngx_http_v3_srv_conf_t *h3scf;
404 335
405 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); 336 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
406 337
338 if (h3scf->max_table_capacity > 0 && !c->read->eof
407 #if (NGX_HTTP_V3_HQ) 339 #if (NGX_HTTP_V3_HQ)
408 if (h3scf->hq) { 340 && !h3scf->hq
409 return;
410 }
411 #endif 341 #endif
412
413 if (h3scf->max_table_capacity > 0 && !c->read->eof
414 && (c->quic->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) == 0) 342 && (c->quic->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) == 0)
415 { 343 {
416 (void) ngx_http_v3_send_cancel_stream(c, c->quic->id); 344 (void) ngx_http_v3_send_cancel_stream(c, c->quic->id);
417 } 345 }
418 346