diff options
author | Igor Sysoev <igor@sysoev.ru> | 2007-12-12 23:53:06 +0300 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2007-12-12 23:53:06 +0300 |
commit | d66b7a8a1ae71d0c4e2d767f4d06f05890169b56 (patch) | |
tree | 93daee7a35133d9c29adf9f744ded5582ab8fac4 | |
parent | af1eaa8cddc9dac82e377815c5ef3fed1053322d (diff) |
r1593, r1595 merge:
server_tokens
-rw-r--r-- | src/http/ngx_http_core_module.c | 9 | ||||
-rw-r--r-- | src/http/ngx_http_core_module.h | 1 | ||||
-rw-r--r-- | src/http/ngx_http_header_filter_module.c | 22 | ||||
-rw-r--r-- | src/http/ngx_http_special_response.c | 22 |
4 files changed, 44 insertions, 10 deletions
diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index b61e2a6b1..dc82adb15 100644 --- 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_commands[] = { 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 *cf) 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 *cf, void *parent, void *child) 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 index 4425d3981..3229dfca8 100644 --- 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 index fedb33c3b..63ecfa135 100644 --- 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_module = { }; -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_t *r) 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_t *r) 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_t *r) *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 index 1797603a0..24b6be7af 100644 --- a/src/http/ngx_http_special_response.c +++ b/src/http/ngx_http_special_response.c @@ -10,13 +10,20 @@ #include <nginx.h> -static u_char error_tail[] = +static u_char error_full_tail[] = "<hr><center>" NGINX_VER "</center>" CRLF "</body>" CRLF "</html>" CRLF ; +static u_char error_tail[] = +"<hr><center>nginx</center>" CRLF +"</body>" CRLF +"</html>" CRLF +; + + static u_char ngx_http_msie_stub[] = "<!-- The padding to disable MSIE's friendly error page -->" CRLF "<!-- The padding to disable MSIE's friendly error page -->" CRLF @@ -471,7 +478,8 @@ ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error) 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_http_request_t *r, ngx_int_t error) } 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) { |