comparison src/http/ngx_http_core_module.c @ 612: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
comparison
equal deleted inserted replaced
611:f02ddde4a240 612:ce857f6b74a7
787 r->connection->unexpected_eof = 0; 787 r->connection->unexpected_eof = 0;
788 788
789 if (!r->internal) { 789 if (!r->internal) {
790 switch (r->headers_in.connection_type) { 790 switch (r->headers_in.connection_type) {
791 case 0: 791 case 0:
792 if (r->http_version > NGX_HTTP_VERSION_10) { 792 r->keepalive = (r->http_version > NGX_HTTP_VERSION_10);
793 r->keepalive = 1;
794 } else {
795 r->keepalive = 0;
796 }
797 break; 793 break;
798 794
799 case NGX_HTTP_CONNECTION_CLOSE: 795 case NGX_HTTP_CONNECTION_CLOSE:
800 r->keepalive = 0; 796 r->keepalive = 0;
801 break; 797 break;
803 case NGX_HTTP_CONNECTION_KEEP_ALIVE: 799 case NGX_HTTP_CONNECTION_KEEP_ALIVE:
804 r->keepalive = 1; 800 r->keepalive = 1;
805 break; 801 break;
806 } 802 }
807 803
808 if (r->headers_in.content_length_n > 0) { 804 r->lingering_close = (r->headers_in.content_length_n > 0);
809 r->lingering_close = 1;
810
811 } else {
812 r->lingering_close = 0;
813 }
814
815 r->phase_handler = 0; 805 r->phase_handler = 0;
816 806
817 } else { 807 } else {
818 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module); 808 cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
819 r->phase_handler = cmcf->phase_engine.server_rewrite_index; 809 r->phase_handler = cmcf->phase_engine.server_rewrite_index;
2998 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child) 2988 ngx_http_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
2999 { 2989 {
3000 ngx_http_core_srv_conf_t *prev = parent; 2990 ngx_http_core_srv_conf_t *prev = parent;
3001 ngx_http_core_srv_conf_t *conf = child; 2991 ngx_http_core_srv_conf_t *conf = child;
3002 2992
2993 ngx_str_t name;
3003 ngx_http_server_name_t *sn; 2994 ngx_http_server_name_t *sn;
3004 2995
3005 /* TODO: it does not merge, it inits only */ 2996 /* TODO: it does not merge, it inits only */
3006 2997
3007 ngx_conf_merge_size_value(conf->connection_pool_size, 2998 ngx_conf_merge_size_value(conf->connection_pool_size,
3029 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1); 3020 ngx_conf_merge_value(conf->merge_slashes, prev->merge_slashes, 1);
3030 3021
3031 ngx_conf_merge_value(conf->underscores_in_headers, 3022 ngx_conf_merge_value(conf->underscores_in_headers,
3032 prev->underscores_in_headers, 0); 3023 prev->underscores_in_headers, 0);
3033 3024
3034 if (conf->server_name.data == NULL) { 3025 if (conf->server_names.nelts == 0) {
3035 ngx_str_set(&conf->server_name, ""); 3026 /* the array has 4 empty preallocated elements, so push can not fail */
3036
3037 sn = ngx_array_push(&conf->server_names); 3027 sn = ngx_array_push(&conf->server_names);
3038 if (sn == NULL) {
3039 return NGX_CONF_ERROR;
3040 }
3041
3042 #if (NGX_PCRE) 3028 #if (NGX_PCRE)
3043 sn->regex = NULL; 3029 sn->regex = NULL;
3044 #endif 3030 #endif
3045 sn->server = conf; 3031 sn->server = conf;
3046 ngx_str_set(&sn->name, ""); 3032 ngx_str_set(&sn->name, "");
3033 }
3034
3035 sn = conf->server_names.elts;
3036 name = sn[0].name;
3037
3038 #if (NGX_PCRE)
3039 if (sn->regex) {
3040 name.len++;
3041 name.data--;
3042 } else
3043 #endif
3044
3045 if (name.data[0] == '.') {
3046 name.len--;
3047 name.data++;
3048 }
3049
3050 conf->server_name.len = name.len;
3051 conf->server_name.data = ngx_pstrdup(cf->pool, &name);
3052 if (conf->server_name.data == NULL) {
3053 return NGX_CONF_ERROR;
3047 } 3054 }
3048 3055
3049 return NGX_CONF_OK; 3056 return NGX_CONF_OK;
3050 } 3057 }
3051 3058
3633 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 3640 ngx_http_core_server_name(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
3634 { 3641 {
3635 ngx_http_core_srv_conf_t *cscf = conf; 3642 ngx_http_core_srv_conf_t *cscf = conf;
3636 3643
3637 u_char ch; 3644 u_char ch;
3638 ngx_str_t *value, name; 3645 ngx_str_t *value;
3639 ngx_uint_t i; 3646 ngx_uint_t i;
3640 ngx_http_server_name_t *sn; 3647 ngx_http_server_name_t *sn;
3641 3648
3642 value = cf->args->elts; 3649 value = cf->args->elts;
3643
3644 ch = value[1].data[0];
3645
3646 if (cscf->server_name.data == NULL) {
3647 name = value[1];
3648
3649 if (ch == '.') {
3650 name.len--;
3651 name.data++;
3652 }
3653
3654 cscf->server_name.len = name.len;
3655 cscf->server_name.data = ngx_pstrdup(cf->pool, &name);
3656 if (cscf->server_name.data == NULL) {
3657 return NGX_CONF_ERROR;
3658 }
3659 }
3660 3650
3661 for (i = 1; i < cf->args->nelts; i++) { 3651 for (i = 1; i < cf->args->nelts; i++) {
3662 3652
3663 ch = value[i].data[0]; 3653 ch = value[i].data[0];
3664 3654
3690 3680
3691 #if (NGX_PCRE) 3681 #if (NGX_PCRE)
3692 sn->regex = NULL; 3682 sn->regex = NULL;
3693 #endif 3683 #endif
3694 sn->server = cscf; 3684 sn->server = cscf;
3695 sn->name = value[i]; 3685
3686 if (ngx_strcasecmp(value[i].data, (u_char *) "$hostname") == 0) {
3687 sn->name = cf->cycle->hostname;
3688
3689 } else {
3690 sn->name = value[i];
3691 }
3696 3692
3697 if (value[i].data[0] != '~') { 3693 if (value[i].data[0] != '~') {
3698 ngx_strlow(sn->name.data, sn->name.data, sn->name.len); 3694 ngx_strlow(sn->name.data, sn->name.data, sn->name.len);
3699 continue; 3695 continue;
3700 } 3696 }