diff src/stream/ngx_stream_variables.c @ 6674:38143d1abdec

Stream: the $status variable. The stream session status is one of the following: 200 - normal completion 403 - access forbidden 500 - internal server error 502 - bad gateway 503 - limit conn
author Roman Arutyunyan <arut@nginx.com>
date Thu, 11 Aug 2016 20:22:23 +0300
parents c6372a40c2a7
children b9f78a4e3597
line wrap: on
line diff
--- a/src/stream/ngx_stream_variables.c
+++ b/src/stream/ngx_stream_variables.c
@@ -25,6 +25,8 @@ static ngx_int_t ngx_stream_variable_byt
     ngx_stream_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_stream_variable_session_time(ngx_stream_session_t *s,
     ngx_stream_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_stream_variable_status(ngx_stream_session_t *s,
+    ngx_stream_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_stream_variable_connection(ngx_stream_session_t *s,
     ngx_stream_variable_value_t *v, uintptr_t data);
 
@@ -70,6 +72,9 @@ static ngx_stream_variable_t  ngx_stream
     { ngx_string("session_time"), NULL, ngx_stream_variable_session_time,
       0, NGX_STREAM_VAR_NOCACHEABLE, 0 },
 
+    { ngx_string("status"), NULL, ngx_stream_variable_status,
+      0, NGX_STREAM_VAR_NOCACHEABLE, 0 },
+
     { ngx_string("connection"), NULL,
       ngx_stream_variable_connection, 0, 0, 0 },
 
@@ -530,6 +535,24 @@ ngx_stream_variable_session_time(ngx_str
 
 
 static ngx_int_t
+ngx_stream_variable_status(ngx_stream_session_t *s,
+    ngx_stream_variable_value_t *v, uintptr_t data)
+{
+    v->data = ngx_pnalloc(s->connection->pool, NGX_INT_T_LEN);
+    if (v->data == NULL) {
+        return NGX_ERROR;
+    }
+
+    v->len = ngx_sprintf(v->data, "%03ui", s->status) - v->data;
+    v->valid = 1;
+    v->no_cacheable = 0;
+    v->not_found = 0;
+
+    return NGX_OK;
+}
+
+
+static ngx_int_t
 ngx_stream_variable_connection(ngx_stream_session_t *s,
     ngx_stream_variable_value_t *v, uintptr_t data)
 {