Mercurial > hg > nginx-mail
diff src/http/ngx_http_core_module.c @ 655:ce857f6b74a7 NGINX_0_9_4
nginx 0.9.4
*) Feature: the "server_name" directive supports the $hostname variable.
*) Feature: 494 code for "Request Header Too Large" error.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Fri, 21 Jan 2011 00:00:00 +0300 |
parents | 9ad199846233 |
children | b4dcae568a2a |
line wrap: on
line diff
--- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -789,11 +789,7 @@ ngx_http_handler(ngx_http_request_t *r) if (!r->internal) { switch (r->headers_in.connection_type) { case 0: - if (r->http_version > NGX_HTTP_VERSION_10) { - r->keepalive = 1; - } else { - r->keepalive = 0; - } + r->keepalive = (r->http_version > NGX_HTTP_VERSION_10); break; case NGX_HTTP_CONNECTION_CLOSE: @@ -805,13 +801,7 @@ ngx_http_handler(ngx_http_request_t *r) break; } - if (r->headers_in.content_length_n > 0) { - r->lingering_close = 1; - - } else { - r->lingering_close = 0; - } - + r->lingering_close = (r->headers_in.content_length_n > 0); r->phase_handler = 0; } else { @@ -3000,6 +2990,7 @@ ngx_http_core_merge_srv_conf(ngx_conf_t ngx_http_core_srv_conf_t *prev = parent; ngx_http_core_srv_conf_t *conf = child; + ngx_str_t name; ngx_http_server_name_t *sn; /* TODO: it does not merge, it inits only */ @@ -3031,14 +3022,9 @@ ngx_http_core_merge_srv_conf(ngx_conf_t ngx_conf_merge_value(conf->underscores_in_headers, prev->underscores_in_headers, 0); - if (conf->server_name.data == NULL) { - ngx_str_set(&conf->server_name, ""); - + if (conf->server_names.nelts == 0) { + /* the array has 4 empty preallocated elements, so push can not fail */ sn = ngx_array_push(&conf->server_names); - if (sn == NULL) { - return NGX_CONF_ERROR; - } - #if (NGX_PCRE) sn->regex = NULL; #endif @@ -3046,6 +3032,27 @@ ngx_http_core_merge_srv_conf(ngx_conf_t ngx_str_set(&sn->name, ""); } + sn = conf->server_names.elts; + name = sn[0].name; + +#if (NGX_PCRE) + if (sn->regex) { + name.len++; + name.data--; + } else +#endif + + if (name.data[0] == '.') { + name.len--; + name.data++; + } + + conf->server_name.len = name.len; + conf->server_name.data = ngx_pstrdup(cf->pool, &name); + if (conf->server_name.data == NULL) { + return NGX_CONF_ERROR; + } + return NGX_CONF_OK; } @@ -3635,29 +3642,12 @@ ngx_http_core_server_name(ngx_conf_t *cf ngx_http_core_srv_conf_t *cscf = conf; u_char ch; - ngx_str_t *value, name; + ngx_str_t *value; ngx_uint_t i; ngx_http_server_name_t *sn; value = cf->args->elts; - ch = value[1].data[0]; - - if (cscf->server_name.data == NULL) { - name = value[1]; - - if (ch == '.') { - name.len--; - name.data++; - } - - cscf->server_name.len = name.len; - cscf->server_name.data = ngx_pstrdup(cf->pool, &name); - if (cscf->server_name.data == NULL) { - return NGX_CONF_ERROR; - } - } - for (i = 1; i < cf->args->nelts; i++) { ch = value[i].data[0]; @@ -3692,7 +3682,13 @@ ngx_http_core_server_name(ngx_conf_t *cf sn->regex = NULL; #endif sn->server = cscf; - sn->name = value[i]; + + if (ngx_strcasecmp(value[i].data, (u_char *) "$hostname") == 0) { + sn->name = cf->cycle->hostname; + + } else { + sn->name = value[i]; + } if (value[i].data[0] != '~') { ngx_strlow(sn->name.data, sn->name.data, sn->name.len);