Mercurial > hg > nginx
comparison src/http/v3/ngx_http_v3_request.c @ 8921:33226ac61076 quic
HTTP/3: merged ngx_http_quic_module into ngx_http_v3_module.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Mon, 06 Dec 2021 13:02:36 +0300 |
parents | d2c193aa8480 |
children | be08b858086a |
comparison
equal
deleted
inserted
replaced
8920:9680f0badc95 | 8921:33226ac61076 |
---|---|
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 static void ngx_http_v3_init_hq_stream(ngx_connection_t *c); | |
14 static void ngx_http_v3_init_request_stream(ngx_connection_t *c); | |
13 static void ngx_http_v3_wait_request_handler(ngx_event_t *rev); | 15 static void ngx_http_v3_wait_request_handler(ngx_event_t *rev); |
14 static void ngx_http_v3_cleanup_request(void *data); | 16 static void ngx_http_v3_cleanup_request(void *data); |
15 static void ngx_http_v3_process_request(ngx_event_t *rev); | 17 static void ngx_http_v3_process_request(ngx_event_t *rev); |
16 static ngx_int_t ngx_http_v3_process_header(ngx_http_request_t *r, | 18 static ngx_int_t ngx_http_v3_process_header(ngx_http_request_t *r, |
17 ngx_str_t *name, ngx_str_t *value); | 19 ngx_str_t *name, ngx_str_t *value); |
52 | 54 |
53 | 55 |
54 void | 56 void |
55 ngx_http_v3_init(ngx_connection_t *c) | 57 ngx_http_v3_init(ngx_connection_t *c) |
56 { | 58 { |
59 ngx_http_connection_t *hc, *phc; | |
60 ngx_http_v3_srv_conf_t *h3scf; | |
61 ngx_http_core_loc_conf_t *clcf; | |
62 | |
63 hc = c->data; | |
64 | |
65 hc->ssl = 1; | |
66 | |
67 if (c->quic == NULL) { | |
68 h3scf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v3_module); | |
69 | |
70 ngx_quic_run(c, &h3scf->quic); | |
71 | |
72 return; | |
73 } | |
74 | |
75 phc = ngx_http_quic_get_connection(c); | |
76 | |
77 if (phc->ssl_servername) { | |
78 hc->ssl_servername = phc->ssl_servername; | |
79 hc->conf_ctx = phc->conf_ctx; | |
80 | |
81 clcf = ngx_http_get_module_loc_conf(hc->conf_ctx, ngx_http_core_module); | |
82 ngx_set_connection_log(c, clcf->error_log); | |
83 } | |
84 | |
85 if (!hc->addr_conf->http3) { | |
86 ngx_http_v3_init_hq_stream(c); | |
87 return; | |
88 } | |
89 | |
90 if (ngx_http_v3_init_session(c) != NGX_OK) { | |
91 ngx_http_close_connection(c); | |
92 return; | |
93 } | |
94 | |
95 if (c->quic->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) { | |
96 ngx_http_v3_init_uni_stream(c); | |
97 | |
98 } else { | |
99 ngx_http_v3_init_request_stream(c); | |
100 } | |
101 } | |
102 | |
103 | |
104 static void | |
105 ngx_http_v3_init_hq_stream(ngx_connection_t *c) | |
106 { | |
107 uint64_t n; | |
108 ngx_event_t *rev; | |
109 ngx_http_connection_t *hc; | |
110 ngx_http_core_loc_conf_t *clcf; | |
111 ngx_http_core_srv_conf_t *cscf; | |
112 | |
113 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init hq stream"); | |
114 | |
115 #if (NGX_STAT_STUB) | |
116 (void) ngx_atomic_fetch_add(ngx_stat_active, 1); | |
117 #endif | |
118 | |
119 hc = c->data; | |
120 | |
121 /* Use HTTP/3 General Protocol Error Code 0x101 for finalization */ | |
122 | |
123 if (c->quic->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) { | |
124 ngx_quic_finalize_connection(c->quic->parent, | |
125 NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR, | |
126 "unexpected uni stream"); | |
127 ngx_http_close_connection(c); | |
128 return; | |
129 } | |
130 | |
131 clcf = ngx_http_get_module_loc_conf(hc->conf_ctx, ngx_http_core_module); | |
132 | |
133 n = c->quic->id >> 2; | |
134 | |
135 if (n >= clcf->keepalive_requests) { | |
136 ngx_quic_finalize_connection(c->quic->parent, | |
137 NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR, | |
138 "reached maximum number of requests"); | |
139 ngx_http_close_connection(c); | |
140 return; | |
141 } | |
142 | |
143 if (ngx_current_msec - c->quic->parent->start_time | |
144 > clcf->keepalive_time) | |
145 { | |
146 ngx_quic_finalize_connection(c->quic->parent, | |
147 NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR, | |
148 "reached maximum time for requests"); | |
149 ngx_http_close_connection(c); | |
150 return; | |
151 } | |
152 | |
153 rev = c->read; | |
154 | |
155 if (rev->ready) { | |
156 rev->handler(rev); | |
157 return; | |
158 } | |
159 | |
160 cscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_core_module); | |
161 | |
162 ngx_add_timer(rev, cscf->client_header_timeout); | |
163 ngx_reusable_connection(c, 1); | |
164 | |
165 if (ngx_handle_read_event(rev, 0) != NGX_OK) { | |
166 ngx_http_close_connection(c); | |
167 return; | |
168 } | |
169 } | |
170 | |
171 | |
172 static void | |
173 ngx_http_v3_init_request_stream(ngx_connection_t *c) | |
174 { | |
57 uint64_t n; | 175 uint64_t n; |
58 ngx_event_t *rev; | 176 ngx_event_t *rev; |
59 ngx_http_connection_t *hc; | 177 ngx_http_connection_t *hc; |
60 ngx_http_v3_session_t *h3c; | 178 ngx_http_v3_session_t *h3c; |
61 ngx_http_core_loc_conf_t *clcf; | 179 ngx_http_core_loc_conf_t *clcf; |
62 ngx_http_core_srv_conf_t *cscf; | 180 ngx_http_core_srv_conf_t *cscf; |
63 | |
64 if (ngx_http_v3_init_session(c) != NGX_OK) { | |
65 ngx_http_close_connection(c); | |
66 return; | |
67 } | |
68 | |
69 if (c->quic->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) { | |
70 ngx_http_v3_init_uni_stream(c); | |
71 return; | |
72 } | |
73 | 181 |
74 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init request stream"); | 182 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init request stream"); |
75 | 183 |
76 #if (NGX_STAT_STUB) | 184 #if (NGX_STAT_STUB) |
77 (void) ngx_atomic_fetch_add(ngx_stat_active, 1); | 185 (void) ngx_atomic_fetch_add(ngx_stat_active, 1); |
277 | 385 |
278 | 386 |
279 void | 387 void |
280 ngx_http_v3_reset_connection(ngx_connection_t *c) | 388 ngx_http_v3_reset_connection(ngx_connection_t *c) |
281 { | 389 { |
390 ngx_http_connection_t *hc; | |
282 ngx_http_v3_srv_conf_t *h3scf; | 391 ngx_http_v3_srv_conf_t *h3scf; |
392 | |
393 hc = ngx_http_quic_get_connection(c); | |
394 | |
395 if (!hc->addr_conf->http3) { | |
396 return; | |
397 } | |
283 | 398 |
284 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); | 399 h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module); |
285 | 400 |
286 if (h3scf->max_table_capacity > 0 && !c->read->eof) { | 401 if (h3scf->max_table_capacity > 0 && !c->read->eof) { |
287 (void) ngx_http_v3_send_cancel_stream(c, c->quic->id); | 402 (void) ngx_http_v3_send_cancel_stream(c, c->quic->id); |