comparison src/http/v3/ngx_http_v3_request.c @ 9081:c851a2ed5ce8 quic

HTTP/3: "quic" parameter of "listen" directive. Now "listen" directve has a new "quic" parameter which enables QUIC protocol for the address. Further, to enable HTTP/3, a new directive "http3" is introduced. The hq-interop protocol is enabled by "http3_hq" as before. Now application protocol is chosen by ALPN. Previously used "http3" parameter of "listen" is deprecated.
author Roman Arutyunyan <arut@nginx.com>
date Mon, 27 Feb 2023 14:00:56 +0400
parents 6bb884dc7291
children 69bae2437d74
comparison
equal deleted inserted replaced
9080:7da4791e0264 9081:c851a2ed5ce8
108 108
109 109
110 ngx_int_t 110 ngx_int_t
111 ngx_http_v3_init(ngx_connection_t *c) 111 ngx_http_v3_init(ngx_connection_t *c)
112 { 112 {
113 unsigned int len;
114 const unsigned char *data;
113 ngx_http_v3_session_t *h3c; 115 ngx_http_v3_session_t *h3c;
116 ngx_http_v3_srv_conf_t *h3scf;
114 ngx_http_core_loc_conf_t *clcf; 117 ngx_http_core_loc_conf_t *clcf;
115 118
116 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init"); 119 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init");
117 120
118 h3c = ngx_http_v3_get_session(c); 121 h3c = ngx_http_v3_get_session(c);
119 clcf = ngx_http_v3_get_module_loc_conf(c, ngx_http_core_module); 122 clcf = ngx_http_v3_get_module_loc_conf(c, ngx_http_core_module);
120 ngx_add_timer(&h3c->keepalive, clcf->keepalive_timeout); 123 ngx_add_timer(&h3c->keepalive, clcf->keepalive_timeout);
121 124
122 #if (NGX_HTTP_V3_HQ) 125 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
123 if (h3c->hq) { 126
124 return NGX_OK; 127 if (h3scf->enable_hq) {
125 } 128 if (!h3scf->enable) {
126 #endif 129 h3c->hq = 1;
130 return NGX_OK;
131 }
132
133 SSL_get0_alpn_selected(c->ssl->connection, &data, &len);
134
135 if (len == sizeof(NGX_HTTP_V3_HQ_PROTO) - 1
136 && ngx_strncmp(data, NGX_HTTP_V3_HQ_PROTO, len) == 0)
137 {
138 h3c->hq = 1;
139 return NGX_OK;
140 }
141 }
127 142
128 return ngx_http_v3_send_settings(c); 143 return ngx_http_v3_send_settings(c);
129 } 144 }
130 145
131 146
145 } 160 }
146 161
147 if (!h3c->goaway) { 162 if (!h3c->goaway) {
148 h3c->goaway = 1; 163 h3c->goaway = 1;
149 164
150 #if (NGX_HTTP_V3_HQ) 165 if (!h3c->hq) {
151 if (!h3c->hq)
152 #endif
153 {
154 (void) ngx_http_v3_send_goaway(c, h3c->next_request_id); 166 (void) ngx_http_v3_send_goaway(c, h3c->next_request_id);
155 } 167 }
156 168
157 ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR, 169 ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
158 "connection shutdown"); 170 "connection shutdown");
203 if (n + 1 == clcf->keepalive_requests 215 if (n + 1 == clcf->keepalive_requests
204 || ngx_current_msec - c->start_time > clcf->keepalive_time) 216 || ngx_current_msec - c->start_time > clcf->keepalive_time)
205 { 217 {
206 h3c->goaway = 1; 218 h3c->goaway = 1;
207 219
208 #if (NGX_HTTP_V3_HQ) 220 if (!h3c->hq) {
209 if (!h3c->hq)
210 #endif
211 {
212 if (ngx_http_v3_send_goaway(c, h3c->next_request_id) != NGX_OK) { 221 if (ngx_http_v3_send_goaway(c, h3c->next_request_id) != NGX_OK) {
213 ngx_http_close_connection(c); 222 ngx_http_close_connection(c);
214 return; 223 return;
215 } 224 }
216 } 225 }
234 ngx_del_timer(&h3c->keepalive); 243 ngx_del_timer(&h3c->keepalive);
235 } 244 }
236 245
237 rev = c->read; 246 rev = c->read;
238 247
239 #if (NGX_HTTP_V3_HQ) 248 if (!h3c->hq) {
240 if (!h3c->hq)
241 #endif
242 {
243 rev->handler = ngx_http_v3_wait_request_handler; 249 rev->handler = ngx_http_v3_wait_request_handler;
244 c->write->handler = ngx_http_empty_handler; 250 c->write->handler = ngx_http_empty_handler;
245 } 251 }
246 252
247 if (rev->ready) { 253 if (rev->ready) {
396 402
397 403
398 void 404 void
399 ngx_http_v3_reset_stream(ngx_connection_t *c) 405 ngx_http_v3_reset_stream(ngx_connection_t *c)
400 { 406 {
407 ngx_http_v3_session_t *h3c;
401 ngx_http_v3_srv_conf_t *h3scf; 408 ngx_http_v3_srv_conf_t *h3scf;
402 409
403 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); 410 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
404 411
405 if (h3scf->max_table_capacity > 0 && !c->read->eof 412 h3c = ngx_http_v3_get_session(c);
406 #if (NGX_HTTP_V3_HQ) 413
407 && !h3scf->hq 414 if (h3scf->max_table_capacity > 0 && !c->read->eof && !h3c->hq
408 #endif
409 && (c->quic->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) == 0) 415 && (c->quic->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) == 0)
410 { 416 {
411 (void) ngx_http_v3_send_cancel_stream(c, c->quic->id); 417 (void) ngx_http_v3_send_cancel_stream(c, c->quic->id);
412 } 418 }
413 419
991 997
992 998
993 static ngx_int_t 999 static ngx_int_t
994 ngx_http_v3_process_request_header(ngx_http_request_t *r) 1000 ngx_http_v3_process_request_header(ngx_http_request_t *r)
995 { 1001 {
996 ssize_t n; 1002 ssize_t n;
997 ngx_buf_t *b; 1003 ngx_buf_t *b;
998 ngx_connection_t *c; 1004 ngx_connection_t *c;
1005 ngx_http_v3_session_t *h3c;
1006 ngx_http_v3_srv_conf_t *h3scf;
999 1007
1000 c = r->connection; 1008 c = r->connection;
1001 1009
1002 if (ngx_http_v3_init_pseudo_headers(r) != NGX_OK) { 1010 if (ngx_http_v3_init_pseudo_headers(r) != NGX_OK) {
1003 return NGX_ERROR; 1011 return NGX_ERROR;
1012 }
1013
1014 h3c = ngx_http_v3_get_session(c);
1015 h3scf = ngx_http_get_module_srv_conf(r, ngx_http_v3_module);
1016
1017 if (!r->http_connection->addr_conf->http3) {
1018 if ((h3c->hq && !h3scf->enable_hq) || (!h3c->hq && !h3scf->enable)) {
1019 ngx_log_error(NGX_LOG_INFO, c->log, 0,
1020 "client attempted to request the server name "
1021 "for which the negotiated protocol is disabled");
1022 ngx_http_finalize_request(r, NGX_HTTP_MISDIRECTED_REQUEST);
1023 return NGX_ERROR;
1024 }
1004 } 1025 }
1005 1026
1006 if (ngx_http_v3_construct_cookie_header(r) != NGX_OK) { 1027 if (ngx_http_v3_construct_cookie_header(r) != NGX_OK) {
1007 return NGX_ERROR; 1028 return NGX_ERROR;
1008 } 1029 }