# HG changeset patch # User Igor Sysoev # Date 1199002527 0 # Node ID 0d9c6fe7502b8dc6fccfd7d4cffc4c5a5f9bce2e # Parent 755e09d5c2711ef125feb675364e70ceba0ec752 axe useless r->server_name 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 @@ -1780,7 +1780,6 @@ ngx_http_subrequest(ngx_http_request_t * sr->in_addr = r->in_addr; sr->port = r->port; sr->port_text = r->port_text; - sr->server_name = r->server_name; sr->variables = r->variables; 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 @@ -160,6 +160,7 @@ ngx_http_header_filter(ngx_http_request_ ngx_list_part_t *part; ngx_table_elt_t *header; ngx_http_core_loc_conf_t *clcf; + ngx_http_core_srv_conf_t *cscf; /* AF_INET only */ u_char addr[INET_ADDRSTRLEN]; @@ -282,7 +283,8 @@ ngx_http_header_filter(ngx_http_request_ r->headers_out.location->hash = 0; if (clcf->server_name_in_redirect) { - host = r->server_name; + cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); + host = cscf->server_name; } else if (r->headers_in.host) { host.len = r->headers_in.host_name_len; diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -340,8 +340,6 @@ ngx_http_init_request(ngx_event_t *rev) r->srv_conf = cscf->ctx->srv_conf; r->loc_conf = cscf->ctx->loc_conf; - r->server_name = cscf->server_name; - rev->handler = ngx_http_process_request_line; #if (NGX_HTTP_SSL) @@ -1512,9 +1510,6 @@ ngx_http_find_virtual_server(ngx_http_re found: - r->server_name.len = len; - r->server_name.data = host; - r->srv_conf = cscf->ctx->srv_conf; r->loc_conf = cscf->ctx->loc_conf; @@ -2605,15 +2600,16 @@ static u_char * ngx_http_log_error_handler(ngx_http_request_t *r, ngx_http_request_t *sr, u_char *buf, size_t len) { - char *uri_separator; - u_char *p; - ngx_http_upstream_t *u; - - if (r->server_name.data) { - p = ngx_snprintf(buf, len, ", server: %V", &r->server_name); - len -= p - buf; - buf = p; - } + char *uri_separator; + u_char *p; + ngx_http_upstream_t *u; + ngx_http_core_srv_conf_t *cscf; + + cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); + + p = ngx_snprintf(buf, len, ", server: %V", &cscf->server_name); + len -= p - buf; + buf = p; if (r->request_line.data == NULL && r->request_start) { for (p = r->request_start; p < r->header_in->last; p++) { diff --git a/src/http/ngx_http_request.h b/src/http/ngx_http_request.h --- a/src/http/ngx_http_request.h +++ b/src/http/ngx_http_request.h @@ -373,7 +373,6 @@ struct ngx_http_request_s { uint32_t in_addr; ngx_uint_t port; ngx_str_t *port_text; /* ":80" */ - ngx_str_t server_name; ngx_http_virtual_names_t *virtual_names; ngx_int_t phase_handler; diff --git a/src/http/ngx_http_variables.c b/src/http/ngx_http_variables.c --- a/src/http/ngx_http_variables.c +++ b/src/http/ngx_http_variables.c @@ -47,6 +47,8 @@ static ngx_int_t ngx_http_variable_docum ngx_http_variable_value_t *v, uintptr_t data); static ngx_int_t ngx_http_variable_request_filename(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); +static ngx_int_t ngx_http_variable_server_name(ngx_http_request_t *r, + ngx_http_variable_value_t *v, uintptr_t data); static ngx_int_t ngx_http_variable_request_method(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data); static ngx_int_t ngx_http_variable_remote_user(ngx_http_request_t *r, @@ -172,8 +174,7 @@ static ngx_http_variable_t ngx_http_cor ngx_http_variable_request_filename, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 }, - { ngx_string("server_name"), NULL, ngx_http_variable_request, - offsetof(ngx_http_request_t, server_name), 0, 0 }, + { ngx_string("server_name"), NULL, ngx_http_variable_server_name, 0, 0, 0 }, { ngx_string("request_method"), NULL, ngx_http_variable_request_method, 0, 0, 0 }, @@ -709,6 +710,8 @@ static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data) { + ngx_http_core_srv_conf_t *cscf; + if (r->host_start == NULL) { if (r->headers_in.host) { @@ -716,8 +719,10 @@ ngx_http_variable_host(ngx_http_request_ v->data = r->headers_in.host->value.data; } else { - v->len = r->server_name.len; - v->data = r->server_name.data; + cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); + + v->len = cscf->server_name.len; + v->data = cscf->server_name.data; } } else if (r->host_end) { @@ -957,6 +962,24 @@ ngx_http_variable_request_filename(ngx_h static ngx_int_t +ngx_http_variable_server_name(ngx_http_request_t *r, + ngx_http_variable_value_t *v, uintptr_t data) +{ + ngx_http_core_srv_conf_t *cscf; + + cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); + + v->len = cscf->server_name.len; + v->valid = 1; + v->no_cacheable = 0; + v->not_found = 0; + v->data = cscf->server_name.data; + + return NGX_OK; +} + + +static ngx_int_t ngx_http_variable_request_method(ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data) {