Mercurial > hg > nginx
comparison src/http/ngx_http_header_filter_module.c @ 6451:155871d773cc
Backed out server_tokens changes.
Backed out changesets: cf3e75cfa951, 6b72414dfb4f, 602dc42035fe, e5076b96fd01.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 22 Mar 2016 16:58:38 +0300 |
parents | e5076b96fd01 |
children | 654d2dae97d3 |
comparison
equal
deleted
inserted
replaced
6450:22c32937a41f | 6451:155871d773cc |
---|---|
44 NULL, /* exit master */ | 44 NULL, /* exit master */ |
45 NGX_MODULE_V1_PADDING | 45 NGX_MODULE_V1_PADDING |
46 }; | 46 }; |
47 | 47 |
48 | 48 |
49 static u_char ngx_http_server_string[] = "Server: nginx" CRLF; | 49 static char ngx_http_server_string[] = "Server: nginx" CRLF; |
50 static u_char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF; | 50 static char ngx_http_server_full_string[] = "Server: " NGINX_VER CRLF; |
51 | 51 |
52 | 52 |
53 static ngx_str_t ngx_http_status_lines[] = { | 53 static ngx_str_t ngx_http_status_lines[] = { |
54 | 54 |
55 ngx_string("200 OK"), | 55 ngx_string("200 OK"), |
150 static ngx_int_t | 150 static ngx_int_t |
151 ngx_http_header_filter(ngx_http_request_t *r) | 151 ngx_http_header_filter(ngx_http_request_t *r) |
152 { | 152 { |
153 u_char *p; | 153 u_char *p; |
154 size_t len; | 154 size_t len; |
155 ngx_str_t host, *status_line, tokens; | 155 ngx_str_t host, *status_line; |
156 ngx_buf_t *b; | 156 ngx_buf_t *b; |
157 ngx_uint_t status, i, port; | 157 ngx_uint_t status, i, port; |
158 ngx_chain_t out; | 158 ngx_chain_t out; |
159 ngx_list_part_t *part; | 159 ngx_list_part_t *part; |
160 ngx_table_elt_t *header; | 160 ngx_table_elt_t *header; |
275 } | 275 } |
276 } | 276 } |
277 | 277 |
278 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); | 278 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); |
279 | 279 |
280 #if (NGX_SUPPRESS_WARN) | |
281 ngx_str_null(&tokens); | |
282 #endif | |
283 | |
284 if (r->headers_out.server == NULL) { | 280 if (r->headers_out.server == NULL) { |
285 if (clcf->server_tokens == 0) { | 281 len += clcf->server_tokens ? sizeof(ngx_http_server_full_string) - 1: |
286 ngx_str_set(&tokens, ngx_http_server_string); | 282 sizeof(ngx_http_server_string) - 1; |
287 | |
288 } else if (clcf->server_tokens == 1) { | |
289 ngx_str_set(&tokens, ngx_http_server_full_string); | |
290 | |
291 } else { | |
292 if (ngx_http_complex_value(r, &clcf->server_tokens_value, &tokens) | |
293 != NGX_OK) | |
294 { | |
295 return NGX_ERROR; | |
296 } | |
297 | |
298 if (tokens.len == 0 | |
299 || (tokens.len == 3 && ngx_strncmp(tokens.data, "off", 3) == 0)) | |
300 { | |
301 ngx_str_set(&tokens, ngx_http_server_string); | |
302 | |
303 } else { | |
304 ngx_str_set(&tokens, ngx_http_server_full_string); | |
305 } | |
306 } | |
307 | |
308 len += tokens.len; | |
309 } | 283 } |
310 | 284 |
311 if (r->headers_out.date == NULL) { | 285 if (r->headers_out.date == NULL) { |
312 len += sizeof("Date: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1; | 286 len += sizeof("Date: Mon, 28 Sep 1970 06:00:00 GMT" CRLF) - 1; |
313 } | 287 } |
480 b->last = ngx_sprintf(b->last, "%03ui ", status); | 454 b->last = ngx_sprintf(b->last, "%03ui ", status); |
481 } | 455 } |
482 *b->last++ = CR; *b->last++ = LF; | 456 *b->last++ = CR; *b->last++ = LF; |
483 | 457 |
484 if (r->headers_out.server == NULL) { | 458 if (r->headers_out.server == NULL) { |
485 b->last = ngx_cpymem(b->last, tokens.data, tokens.len); | 459 if (clcf->server_tokens) { |
460 p = (u_char *) ngx_http_server_full_string; | |
461 len = sizeof(ngx_http_server_full_string) - 1; | |
462 | |
463 } else { | |
464 p = (u_char *) ngx_http_server_string; | |
465 len = sizeof(ngx_http_server_string) - 1; | |
466 } | |
467 | |
468 b->last = ngx_cpymem(b->last, p, len); | |
486 } | 469 } |
487 | 470 |
488 if (r->headers_out.date == NULL) { | 471 if (r->headers_out.date == NULL) { |
489 b->last = ngx_cpymem(b->last, "Date: ", sizeof("Date: ") - 1); | 472 b->last = ngx_cpymem(b->last, "Date: ", sizeof("Date: ") - 1); |
490 b->last = ngx_cpymem(b->last, ngx_cached_http_time.data, | 473 b->last = ngx_cpymem(b->last, ngx_cached_http_time.data, |