# HG changeset patch # User Igor Sysoev # Date 1197492786 0 # Node ID 0a174d921f1ea336ddc07444470271c9214424c8 # Parent 461d00e8a2a99efba1f602b9cb343cb353e16b6d r1593, r1595 merge: server_tokens diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -432,6 +432,13 @@ static ngx_command_t ngx_http_core_comm 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, @@ -2370,6 +2377,7 @@ ngx_http_core_create_loc_conf(ngx_conf_t 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; @@ -2554,6 +2562,7 @@ ngx_http_core_merge_loc_conf(ngx_conf_t 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); if (conf->open_files == NULL) { conf->open_files = prev->open_files; diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -285,6 +285,7 @@ struct ngx_http_core_loc_conf_s { 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 --git a/src/http/ngx_http_header_filter_module.c b/src/http/ngx_http_header_filter_module.c --- a/src/http/ngx_http_header_filter_module.c +++ b/src/http/ngx_http_header_filter_module.c @@ -45,7 +45,8 @@ ngx_module_t ngx_http_header_filter_mod }; -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 @@ ngx_http_header_filter(ngx_http_request_ 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 @@ ngx_http_header_filter(ngx_http_request_ 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 @@ ngx_http_header_filter(ngx_http_request_ *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 = (u_char *) ngx_http_server_full_string; + len = sizeof(ngx_http_server_full_string) - 1; + + } else { + p = (u_char *) 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 --git a/src/http/ngx_http_special_response.c b/src/http/ngx_http_special_response.c --- a/src/http/ngx_http_special_response.c +++ b/src/http/ngx_http_special_response.c @@ -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 @@ ngx_http_special_response_handler(ngx_ht 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 @@ ngx_http_special_response_handler(ngx_ht } 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) {