comparison src/http/v3/ngx_http_v3_request.c @ 8725:98c4020f1c9a quic

HTTP/3: keepalive timeout. This timeout limits the time when no client request streams exist.
author Roman Arutyunyan <arut@nginx.com>
date Tue, 30 Mar 2021 16:48:38 +0300
parents fc64ab301bad
children a64255c01dab
comparison
equal deleted inserted replaced
8724:fc64ab301bad 8725:98c4020f1c9a
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_cleanup_request(void *data);
13 static void ngx_http_v3_process_request(ngx_event_t *rev); 14 static void ngx_http_v3_process_request(ngx_event_t *rev);
14 static ngx_int_t ngx_http_v3_process_header(ngx_http_request_t *r, 15 static ngx_int_t ngx_http_v3_process_header(ngx_http_request_t *r,
15 ngx_str_t *name, ngx_str_t *value); 16 ngx_str_t *name, ngx_str_t *value);
16 static ngx_int_t ngx_http_v3_validate_header(ngx_http_request_t *r, 17 static ngx_int_t ngx_http_v3_validate_header(ngx_http_request_t *r,
17 ngx_str_t *name, ngx_str_t *value); 18 ngx_str_t *name, ngx_str_t *value);
53 { 54 {
54 size_t size; 55 size_t size;
55 uint64_t n; 56 uint64_t n;
56 ngx_buf_t *b; 57 ngx_buf_t *b;
57 ngx_event_t *rev; 58 ngx_event_t *rev;
59 ngx_pool_cleanup_t *cln;
58 ngx_http_request_t *r; 60 ngx_http_request_t *r;
59 ngx_http_connection_t *hc; 61 ngx_http_connection_t *hc;
62 ngx_http_v3_connection_t *h3c;
60 ngx_http_core_loc_conf_t *clcf; 63 ngx_http_core_loc_conf_t *clcf;
61 ngx_http_core_srv_conf_t *cscf; 64 ngx_http_core_srv_conf_t *cscf;
62 65
63 if (ngx_http_v3_init_session(c) != NGX_OK) { 66 if (ngx_http_v3_init_session(c) != NGX_OK) {
64 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR, 67 ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR,
96 99
97 ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR, 100 ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
98 "reached maximum number of requests"); 101 "reached maximum number of requests");
99 } 102 }
100 103
104 cln = ngx_pool_cleanup_add(c->pool, 0);
105 if (cln == NULL) {
106 ngx_http_close_connection(c);
107 return;
108 }
109
110 cln->handler = ngx_http_v3_cleanup_request;
111 cln->data = c;
112
113 h3c = c->quic->parent->data;
114 h3c->nrequests++;
115
116 if (h3c->keepalive.timer_set) {
117 ngx_del_timer(&h3c->keepalive);
118 }
119
101 cscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_core_module); 120 cscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_core_module);
102 121
103 size = cscf->client_header_buffer_size; 122 size = cscf->client_header_buffer_size;
104 123
105 b = c->buffer; 124 b = c->buffer;
149 168
150 rev = c->read; 169 rev = c->read;
151 rev->handler = ngx_http_v3_process_request; 170 rev->handler = ngx_http_v3_process_request;
152 171
153 ngx_http_v3_process_request(rev); 172 ngx_http_v3_process_request(rev);
173 }
174
175
176 static void
177 ngx_http_v3_cleanup_request(void *data)
178 {
179 ngx_connection_t *c = data;
180
181 ngx_http_core_loc_conf_t *clcf;
182 ngx_http_v3_connection_t *h3c;
183
184 h3c = c->quic->parent->data;
185
186 if (--h3c->nrequests == 0) {
187 clcf = ngx_http_v3_get_module_loc_conf(c, ngx_http_core_module);
188 ngx_add_timer(&h3c->keepalive, clcf->keepalive_timeout);
189 }
154 } 190 }
155 191
156 192
157 static void 193 static void
158 ngx_http_v3_process_request(ngx_event_t *rev) 194 ngx_http_v3_process_request(ngx_event_t *rev)