# HG changeset patch # User Igor Sysoev # Date 1193048254 0 # Node ID 128ea9efb8247f3d0c1d5410011b9c85f4bb9e14 # Parent 135202406b0c1918dfaf28bd7d23b3db0c9b03bd server_tokens diff -r 135202406b0c -r 128ea9efb824 src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c Mon Oct 22 10:15:48 2007 +0000 +++ b/src/http/ngx_http_core_module.c Mon Oct 22 10:17:34 2007 +0000 @@ -434,6 +434,13 @@ offsetof(ngx_http_core_loc_conf_t, recursive_error_pages), NULL }, + { ngx_string("server_tokens"), + NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, + ngx_conf_set_flag_slot, + NGX_HTTP_LOC_CONF_OFFSET, + offsetof(ngx_http_core_loc_conf_t, server_tokens), + NULL }, + { ngx_string("error_page"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF |NGX_CONF_2MORE, @@ -2390,6 +2397,7 @@ lcf->msie_refresh = NGX_CONF_UNSET; lcf->log_not_found = NGX_CONF_UNSET; lcf->recursive_error_pages = NGX_CONF_UNSET; + lcf->server_tokens = NGX_CONF_UNSET; lcf->types_hash_max_size = NGX_CONF_UNSET_UINT; lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT; lcf->open_file_cache = NGX_CONF_UNSET_PTR; @@ -2578,6 +2586,7 @@ ngx_conf_merge_value(conf->log_not_found, prev->log_not_found, 1); ngx_conf_merge_value(conf->recursive_error_pages, prev->recursive_error_pages, 0); + ngx_conf_merge_value(conf->server_tokens, prev->server_tokens, 1); ngx_conf_merge_ptr_value(conf->open_file_cache, prev->open_file_cache, NULL); diff -r 135202406b0c -r 128ea9efb824 src/http/ngx_http_core_module.h --- a/src/http/ngx_http_core_module.h Mon Oct 22 10:15:48 2007 +0000 +++ b/src/http/ngx_http_core_module.h Mon Oct 22 10:17:34 2007 +0000 @@ -285,6 +285,7 @@ ngx_flag_t msie_refresh; /* msie_refresh */ ngx_flag_t log_not_found; /* log_not_found */ ngx_flag_t recursive_error_pages; /* recursive_error_pages */ + ngx_flag_t server_tokens; /* server_tokens */ ngx_array_t *error_pages; /* error_page */ diff -r 135202406b0c -r 128ea9efb824 src/http/ngx_http_header_filter_module.c --- a/src/http/ngx_http_header_filter_module.c Mon Oct 22 10:15:48 2007 +0000 +++ b/src/http/ngx_http_header_filter_module.c Mon Oct 22 10:17:34 2007 +0000 @@ -45,7 +45,8 @@ }; -static char ngx_http_server_string[] = "Server: " NGINX_VER CRLF; +static char ngx_http_server_string[] = "Server: nginx" CRLF; +static char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF; static ngx_str_t ngx_http_status_lines[] = { @@ -237,8 +238,11 @@ len += ngx_http_status_lines[status].len; } + clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + if (r->headers_out.server == NULL) { - len += sizeof(ngx_http_server_string) - 1; + len += clcf->server_tokens ? sizeof(ngx_http_server_full_string) - 1: + sizeof(ngx_http_server_string) - 1; } if (r->headers_out.date == NULL) { @@ -268,8 +272,6 @@ len += sizeof("Last-Modified: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1; } - clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); - if (r->headers_out.location && r->headers_out.location->value.len && r->headers_out.location->value.data[0] == '/') @@ -365,8 +367,16 @@ *b->last++ = CR; *b->last++ = LF; if (r->headers_out.server == NULL) { - b->last = ngx_cpymem(b->last, ngx_http_server_string, - sizeof(ngx_http_server_string) - 1); + if (clcf->server_tokens) { + p = ngx_http_server_full_string; + len = sizeof(ngx_http_server_full_string) - 1; + + } else { + p = ngx_http_server_string; + len = sizeof(ngx_http_server_string) - 1; + } + + b->last = ngx_cpymem(b->last, p, len); } if (r->headers_out.date == NULL) { diff -r 135202406b0c -r 128ea9efb824 src/http/ngx_http_special_response.c --- a/src/http/ngx_http_special_response.c Mon Oct 22 10:15:48 2007 +0000 +++ b/src/http/ngx_http_special_response.c Mon Oct 22 10:17:34 2007 +0000 @@ -10,8 +10,15 @@ #include +static u_char error_full_tail[] = +"
" NGINX_VER "
" CRLF +"" CRLF +"" CRLF +; + + static u_char error_tail[] = -"
" NGINX_VER "
" CRLF +"
nginx
" CRLF "" CRLF "" CRLF ; @@ -471,7 +478,8 @@ if (!r->zero_body) { if (error_pages[err].len) { r->headers_out.content_length_n = error_pages[err].len - + sizeof(error_tail) - 1; + + (clcf->server_tokens ? sizeof(error_full_tail) - 1: + sizeof(error_tail) - 1); if (clcf->msie_padding && r->headers_in.msie @@ -568,8 +576,14 @@ } b->memory = 1; - b->pos = error_tail; - b->last = error_tail + sizeof(error_tail) - 1; + + if (clcf->server_tokens) { + b->pos = error_full_tail; + b->last = error_full_tail + sizeof(error_full_tail) - 1; + } else { + b->pos = error_tail; + b->last = error_tail + sizeof(error_tail) - 1; + } cl->next = ngx_alloc_chain_link(r->pool); if (cl->next == NULL) {