[PATCH] Stream: $server_name

Sergey Kandaurov pluknet at nginx.com
Fri Mar 22 14:41:12 UTC 2024


# HG changeset patch
# User Sergey Kandaurov <pluknet at nginx.com>
# Date 1711118390 -14400
#      Fri Mar 22 18:39:50 2024 +0400
# Node ID 96ff3f8b7e508a345c18bb1e1071f248f1e5a75c
# Parent  6317e21a15e083a215b52480b8ef473fdfe34158
Stream: $server_name.

diff --git a/src/stream/ngx_stream_variables.c b/src/stream/ngx_stream_variables.c
--- a/src/stream/ngx_stream_variables.c
+++ b/src/stream/ngx_stream_variables.c
@@ -29,6 +29,8 @@ static ngx_int_t ngx_stream_variable_ser
     ngx_stream_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_stream_variable_server_port(ngx_stream_session_t *s,
     ngx_stream_variable_value_t *v, uintptr_t data);
+static ngx_int_t ngx_stream_variable_server_name(ngx_stream_session_t *s,
+    ngx_stream_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_stream_variable_bytes(ngx_stream_session_t *s,
     ngx_stream_variable_value_t *v, uintptr_t data);
 static ngx_int_t ngx_stream_variable_session_time(ngx_stream_session_t *s,
@@ -91,6 +93,9 @@ static ngx_stream_variable_t  ngx_stream
     { ngx_string("server_port"), NULL,
       ngx_stream_variable_server_port, 0, 0, 0 },
 
+    { ngx_string("server_name"), NULL, ngx_stream_variable_server_name,
+      0, 0, 0 },
+
     { ngx_string("bytes_sent"), NULL, ngx_stream_variable_bytes,
       0, 0, 0 },
 
@@ -722,6 +727,24 @@ ngx_stream_variable_server_port(ngx_stre
 
 
 static ngx_int_t
+ngx_stream_variable_server_name(ngx_stream_session_t *s,
+    ngx_stream_variable_value_t *v, uintptr_t data)
+{
+    ngx_stream_core_srv_conf_t  *cscf;
+
+    cscf = ngx_stream_get_module_srv_conf(s, ngx_stream_core_module);
+
+    v->len = cscf->server_name.len;
+    v->valid = 1;
+    v->no_cacheable = 0;
+    v->not_found = 0;
+    v->data = cscf->server_name.data;
+
+    return NGX_OK;
+}
+
+
+static ngx_int_t
 ngx_stream_variable_bytes(ngx_stream_session_t *s,
     ngx_stream_variable_value_t *v, uintptr_t data)
 {


More information about the nginx-devel mailing list