Welcome! Log In Create A New Profile

Advanced

[nginx] Added $connection_time variable.

Maxim Dounin
April 07, 2021 06:36PM
details: https://hg.nginx.org/nginx/rev/6d4f7d5e279f
branches:
changeset: 7821:6d4f7d5e279f
user: Maxim Dounin <mdounin@mdounin.ru>
date: Thu Apr 08 00:16:17 2021 +0300
description:
Added $connection_time variable.

diffstat:

src/http/ngx_http_variables.c | 30 ++++++++++++++++++++++++++++++
1 files changed, 30 insertions(+), 0 deletions(-)

diffs (54 lines):

diff -r fdc3d40979b0 -r 6d4f7d5e279f src/http/ngx_http_variables.c
--- a/src/http/ngx_http_variables.c Thu Apr 08 00:15:48 2021 +0300
+++ b/src/http/ngx_http_variables.c Thu Apr 08 00:16:17 2021 +0300
@@ -129,6 +129,8 @@ static ngx_int_t ngx_http_variable_conne
ngx_http_variable_value_t *v, uintptr_t data);
static ngx_int_t ngx_http_variable_connection_requests(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_http_variable_connection_time(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data);

static ngx_int_t ngx_http_variable_nginx_version(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data);
@@ -342,6 +344,9 @@ static ngx_http_variable_t ngx_http_cor
{ ngx_string("connection_requests"), NULL,
ngx_http_variable_connection_requests, 0, 0, 0 },

+ { ngx_string("connection_time"), NULL, ngx_http_variable_connection_time,
+ 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
+
{ ngx_string("nginx_version"), NULL, ngx_http_variable_nginx_version,
0, 0, 0 },

@@ -2253,6 +2258,31 @@ ngx_http_variable_connection_requests(ng


static ngx_int_t
+ngx_http_variable_connection_time(ngx_http_request_t *r,
+ ngx_http_variable_value_t *v, uintptr_t data)
+{
+ u_char *p;
+ ngx_msec_int_t ms;
+
+ p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4);
+ if (p == NULL) {
+ return NGX_ERROR;
+ }
+
+ ms = ngx_current_msec - r->connection->start_time;
+ ms = ngx_max(ms, 0);
+
+ v->len = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000) - p;
+ v->valid = 1;
+ v->no_cacheable = 0;
+ v->not_found = 0;
+ v->data = p;
+
+ return NGX_OK;
+}
+
+
+static ngx_int_t
ngx_http_variable_nginx_version(ngx_http_request_t *r,
ngx_http_variable_value_t *v, uintptr_t data)
{
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Added $connection_time variable.

Maxim Dounin 157 April 07, 2021 06:36PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 85
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready