Mercurial > hg > nginx
comparison src/http/ngx_http_variables.c @ 7821:6d4f7d5e279f
Added $connection_time variable.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Thu, 08 Apr 2021 00:16:17 +0300 |
parents | 028b16e2798f |
children | ae7c767aa491 |
comparison
equal
deleted
inserted
replaced
7820:fdc3d40979b0 | 7821:6d4f7d5e279f |
---|---|
126 ngx_http_variable_value_t *v, uintptr_t data); | 126 ngx_http_variable_value_t *v, uintptr_t data); |
127 | 127 |
128 static ngx_int_t ngx_http_variable_connection(ngx_http_request_t *r, | 128 static ngx_int_t ngx_http_variable_connection(ngx_http_request_t *r, |
129 ngx_http_variable_value_t *v, uintptr_t data); | 129 ngx_http_variable_value_t *v, uintptr_t data); |
130 static ngx_int_t ngx_http_variable_connection_requests(ngx_http_request_t *r, | 130 static ngx_int_t ngx_http_variable_connection_requests(ngx_http_request_t *r, |
131 ngx_http_variable_value_t *v, uintptr_t data); | |
132 static ngx_int_t ngx_http_variable_connection_time(ngx_http_request_t *r, | |
131 ngx_http_variable_value_t *v, uintptr_t data); | 133 ngx_http_variable_value_t *v, uintptr_t data); |
132 | 134 |
133 static ngx_int_t ngx_http_variable_nginx_version(ngx_http_request_t *r, | 135 static ngx_int_t ngx_http_variable_nginx_version(ngx_http_request_t *r, |
134 ngx_http_variable_value_t *v, uintptr_t data); | 136 ngx_http_variable_value_t *v, uintptr_t data); |
135 static ngx_int_t ngx_http_variable_hostname(ngx_http_request_t *r, | 137 static ngx_int_t ngx_http_variable_hostname(ngx_http_request_t *r, |
340 ngx_http_variable_connection, 0, 0, 0 }, | 342 ngx_http_variable_connection, 0, 0, 0 }, |
341 | 343 |
342 { ngx_string("connection_requests"), NULL, | 344 { ngx_string("connection_requests"), NULL, |
343 ngx_http_variable_connection_requests, 0, 0, 0 }, | 345 ngx_http_variable_connection_requests, 0, 0, 0 }, |
344 | 346 |
347 { ngx_string("connection_time"), NULL, ngx_http_variable_connection_time, | |
348 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, | |
349 | |
345 { ngx_string("nginx_version"), NULL, ngx_http_variable_nginx_version, | 350 { ngx_string("nginx_version"), NULL, ngx_http_variable_nginx_version, |
346 0, 0, 0 }, | 351 0, 0, 0 }, |
347 | 352 |
348 { ngx_string("hostname"), NULL, ngx_http_variable_hostname, | 353 { ngx_string("hostname"), NULL, ngx_http_variable_hostname, |
349 0, 0, 0 }, | 354 0, 0, 0 }, |
2241 if (p == NULL) { | 2246 if (p == NULL) { |
2242 return NGX_ERROR; | 2247 return NGX_ERROR; |
2243 } | 2248 } |
2244 | 2249 |
2245 v->len = ngx_sprintf(p, "%ui", r->connection->requests) - p; | 2250 v->len = ngx_sprintf(p, "%ui", r->connection->requests) - p; |
2251 v->valid = 1; | |
2252 v->no_cacheable = 0; | |
2253 v->not_found = 0; | |
2254 v->data = p; | |
2255 | |
2256 return NGX_OK; | |
2257 } | |
2258 | |
2259 | |
2260 static ngx_int_t | |
2261 ngx_http_variable_connection_time(ngx_http_request_t *r, | |
2262 ngx_http_variable_value_t *v, uintptr_t data) | |
2263 { | |
2264 u_char *p; | |
2265 ngx_msec_int_t ms; | |
2266 | |
2267 p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4); | |
2268 if (p == NULL) { | |
2269 return NGX_ERROR; | |
2270 } | |
2271 | |
2272 ms = ngx_current_msec - r->connection->start_time; | |
2273 ms = ngx_max(ms, 0); | |
2274 | |
2275 v->len = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000) - p; | |
2246 v->valid = 1; | 2276 v->valid = 1; |
2247 v->no_cacheable = 0; | 2277 v->no_cacheable = 0; |
2248 v->not_found = 0; | 2278 v->not_found = 0; |
2249 v->data = p; | 2279 v->data = p; |
2250 | 2280 |