[nginx] Reconsidered server_tokens with an empty value.

Ruslan Ermilov ru at nginx.com
Tue Mar 22 13:32:11 UTC 2016


details:   http://hg.nginx.org/nginx/rev/e5076b96fd01
branches:  
changeset: 6449:e5076b96fd01
user:      Ruslan Ermilov <ru at nginx.com>
date:      Tue Mar 22 15:52:28 2016 +0300
description:
Reconsidered server_tokens with an empty value.

An empty value will be treated as "off".

diffstat:

 src/http/ngx_http_header_filter_module.c |   8 ++++----
 src/http/ngx_http_special_response.c     |  15 +++------------
 src/http/v2/ngx_http_v2_filter_module.c  |   8 ++++----
 3 files changed, 11 insertions(+), 20 deletions(-)

diffs (94 lines):

diff -r 4d1d3c2530e0 -r e5076b96fd01 src/http/ngx_http_header_filter_module.c
--- a/src/http/ngx_http_header_filter_module.c	Mon Mar 21 17:04:21 2016 +0300
+++ b/src/http/ngx_http_header_filter_module.c	Tue Mar 22 15:52:28 2016 +0300
@@ -295,12 +295,12 @@ ngx_http_header_filter(ngx_http_request_
                 return NGX_ERROR;
             }
 
-            if (tokens.len == 3
-                && ngx_strncmp(tokens.data, "off", 3) == 0)
+            if (tokens.len == 0
+                || (tokens.len == 3 && ngx_strncmp(tokens.data, "off", 3) == 0))
             {
                 ngx_str_set(&tokens, ngx_http_server_string);
 
-            } else if (tokens.len) {
+            } else {
                 ngx_str_set(&tokens, ngx_http_server_full_string);
             }
         }
@@ -481,7 +481,7 @@ ngx_http_header_filter(ngx_http_request_
     }
     *b->last++ = CR; *b->last++ = LF;
 
-    if (r->headers_out.server == NULL && tokens.len) {
+    if (r->headers_out.server == NULL) {
         b->last = ngx_cpymem(b->last, tokens.data, tokens.len);
     }
 
diff -r 4d1d3c2530e0 -r e5076b96fd01 src/http/ngx_http_special_response.c
--- a/src/http/ngx_http_special_response.c	Mon Mar 21 17:04:21 2016 +0300
+++ b/src/http/ngx_http_special_response.c	Tue Mar 22 15:52:28 2016 +0300
@@ -32,12 +32,6 @@ static u_char ngx_http_error_tail[] =
 ;
 
 
-static u_char ngx_http_error_no_tail[] =
-"</body>" CRLF
-"</html>" CRLF
-;
-
-
 static u_char ngx_http_msie_padding[] =
 "<!-- a padding to disable MSIE and Chrome friendly error page -->" CRLF
 "<!-- a padding to disable MSIE and Chrome friendly error page -->" CRLF
@@ -638,16 +632,13 @@ ngx_http_send_special_response(ngx_http_
                 return NGX_ERROR;
             }
 
-            if (tokens.len == 3
-                && ngx_strncmp(tokens.data, "off", 3) == 0)
+            if (tokens.len == 0
+                || (tokens.len == 3 && ngx_strncmp(tokens.data, "off", 3) == 0))
             {
                 ngx_str_set(&tail, ngx_http_error_tail);
 
-            } else if (tokens.len) {
+            } else {
                 ngx_str_set(&tail, ngx_http_error_full_tail);
-
-            } else {
-                ngx_str_set(&tail, ngx_http_error_no_tail);
             }
         }
 
diff -r 4d1d3c2530e0 -r e5076b96fd01 src/http/v2/ngx_http_v2_filter_module.c
--- a/src/http/v2/ngx_http_v2_filter_module.c	Mon Mar 21 17:04:21 2016 +0300
+++ b/src/http/v2/ngx_http_v2_filter_module.c	Tue Mar 22 15:52:28 2016 +0300
@@ -252,14 +252,14 @@ ngx_http_v2_header_filter(ngx_http_reque
                 return NGX_ERROR;
             }
 
-            if (tokens.len == 3
-                && ngx_strncmp(tokens.data, "off", 3) == 0)
+            if (tokens.len == 0
+                || (tokens.len == 3 && ngx_strncmp(tokens.data, "off", 3) == 0))
             {
                 server_tokens = 0;
                 len += 1 + sizeof(nginx);
                 ngx_str_set(&tokens, "nginx");
 
-            } else if (tokens.len) {
+            } else {
                 server_tokens = 1;
                 len += 1 + nginx_ver_len;
                 ngx_str_set(&tokens, NGINX_VER);
@@ -468,7 +468,7 @@ ngx_http_v2_header_filter(ngx_http_reque
         pos = ngx_sprintf(pos, "%03ui", r->headers_out.status);
     }
 
-    if (r->headers_out.server == NULL && tokens.len) {
+    if (r->headers_out.server == NULL) {
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
                        "http2 output header: \"server: %V\"",
                        &tokens);



More information about the nginx-devel mailing list