comparison src/http/ngx_http_core_module.c @ 138:8e6d4d96ec4c NGINX_0_3_16

nginx 0.3.16 *) Feature: the ngx_http_map_module. *) Feature: the "types_hash_max_size" and "types_hash_bucket_size" directives. *) Feature: the "ssi_value_length" directive. *) Feature: the "worker_rlimit_core" directive. *) Workaround: the connection number in logs was always 1 if nginx was built by the icc 8.1 or 9.0 compilers with optimization for Pentium 4. *) Bugfix: the "config timefmt" SSI command set incorrect time format. *) Bugfix: nginx did not close connection to IMAP/POP3 backend for the SSL connections; bug appeared in 0.3.13. Thanks to Rob Mueller. *) Bugfix: segmentation fault may occurred in at SSL shutdown; bug appeared in 0.3.13.
author Igor Sysoev <http://sysoev.ru>
date Fri, 16 Dec 2005 00:00:00 +0300
parents 91372f004adf
children 84910468f6de
comparison
equal deleted inserted replaced
137:768f51dd150b 138:8e6d4d96ec4c
160 { ngx_string("server_name"), 160 { ngx_string("server_name"),
161 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE, 161 NGX_HTTP_SRV_CONF|NGX_CONF_1MORE,
162 ngx_http_core_server_name, 162 ngx_http_core_server_name,
163 NGX_HTTP_SRV_CONF_OFFSET, 163 NGX_HTTP_SRV_CONF_OFFSET,
164 0, 164 0,
165 NULL },
166
167 { ngx_string("types_hash_max_size"),
168 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
169 ngx_conf_set_num_slot,
170 NGX_HTTP_LOC_CONF_OFFSET,
171 offsetof(ngx_http_core_loc_conf_t, types_hash_max_size),
172 NULL },
173
174 { ngx_string("types_hash_bucket_size"),
175 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
176 ngx_conf_set_num_slot,
177 NGX_HTTP_LOC_CONF_OFFSET,
178 offsetof(ngx_http_core_loc_conf_t, types_hash_bucket_size),
165 NULL }, 179 NULL },
166 180
167 { ngx_string("types"), 181 { ngx_string("types"),
168 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF 182 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF
169 |NGX_CONF_BLOCK|NGX_CONF_NOARGS, 183 |NGX_CONF_BLOCK|NGX_CONF_NOARGS,
847 861
848 ngx_int_t 862 ngx_int_t
849 ngx_http_set_content_type(ngx_http_request_t *r) 863 ngx_http_set_content_type(ngx_http_request_t *r)
850 { 864 {
851 u_char c, *p, *exten; 865 u_char c, *p, *exten;
852 uint32_t key; 866 ngx_str_t *type;
853 ngx_uint_t i; 867 ngx_uint_t i;
854 ngx_http_type_t *type;
855 ngx_http_core_loc_conf_t *clcf; 868 ngx_http_core_loc_conf_t *clcf;
856 869
857 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 870 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
858 871
859 if (r->exten.len) { 872 if (r->exten.len) {
874 887
875 exten = p; 888 exten = p;
876 889
877 for (i = 0; i < r->exten.len; i++) { 890 for (i = 0; i < r->exten.len; i++) {
878 c = r->exten.data[i]; 891 c = r->exten.data[i];
879 if (c >= 'A' && c <= 'Z') { 892 *p++ = ngx_tolower(c);
880 *p++ = (u_char) (c | 0x20);
881 } else {
882 *p++ = c;
883 }
884 } 893 }
885 894
886 r->exten.data = exten; 895 r->exten.data = exten;
887 } 896 }
888 897
889 r->low_case_exten = 1; 898 r->low_case_exten = 1;
890 } 899 }
891 900
892 ngx_http_types_hash_key(key, r->exten); 901 type = ngx_hash_find(&clcf->types_hash,
893 902 ngx_hash_key(r->exten.data, r->exten.len),
894 type = clcf->types[key].elts; 903 r->exten.data, r->exten.len);
895 for (i = 0; i < clcf->types[key].nelts; i++) { 904
896 if (r->exten.len != type[i].exten.len) { 905 if (type) {
897 continue; 906 r->headers_out.content_type = *type;
898 } 907 return NGX_OK;
899 908 }
900 if (ngx_memcmp(r->exten.data, type[i].exten.data, r->exten.len) 909 }
901 == 0) 910
902 { 911 r->headers_out.content_type = clcf->default_type;
903 r->headers_out.content_type = type[i].type;
904 break;
905 }
906 }
907 }
908
909 if (r->headers_out.content_type.len == 0) {
910 r->headers_out.content_type= clcf->default_type;
911 }
912 912
913 return NGX_OK; 913 return NGX_OK;
914 } 914 }
915 915
916 916
1634 static char * 1634 static char *
1635 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf) 1635 ngx_http_core_type(ngx_conf_t *cf, ngx_command_t *dummy, void *conf)
1636 { 1636 {
1637 ngx_http_core_loc_conf_t *lcf = conf; 1637 ngx_http_core_loc_conf_t *lcf = conf;
1638 1638
1639 uint32_t key; 1639 ngx_str_t *value, *content_type, *old;
1640 ngx_uint_t i; 1640 ngx_uint_t i, n;
1641 ngx_str_t *value; 1641 ngx_hash_key_t *type;
1642 ngx_http_type_t *type;
1643 1642
1644 if (lcf->types == NULL) { 1643 if (lcf->types == NULL) {
1645 lcf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME 1644 lcf->types = ngx_array_create(cf->pool, 64, sizeof(ngx_hash_key_t));
1646 * sizeof(ngx_array_t));
1647 if (lcf->types == NULL) { 1645 if (lcf->types == NULL) {
1648 return NGX_CONF_ERROR; 1646 return NGX_CONF_ERROR;
1649 } 1647 }
1650 1648 }
1651 for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) { 1649
1652 if (ngx_array_init(&lcf->types[i], cf->pool, 4, 1650 content_type = ngx_palloc(cf->pool, sizeof(ngx_str_t));
1653 sizeof(ngx_http_type_t)) == NGX_ERROR) 1651 if (content_type == NULL) {
1654 { 1652 return NGX_CONF_ERROR;
1655 return NGX_CONF_ERROR;
1656 }
1657 }
1658 } 1653 }
1659 1654
1660 value = cf->args->elts; 1655 value = cf->args->elts;
1656 *content_type = value[0];
1661 1657
1662 for (i = 1; i < cf->args->nelts; i++) { 1658 for (i = 1; i < cf->args->nelts; i++) {
1663 ngx_http_types_hash_key(key, value[i]); 1659
1664 1660 for (n = 0; n < value[i].len; n++) {
1665 type = ngx_array_push(&lcf->types[key]); 1661 value[i].data[n] = ngx_tolower(value[i].data[n]);
1662 }
1663
1664 type = lcf->types->elts;
1665 for (n = 0; n < lcf->types->nelts; n++) {
1666 if (ngx_strcmp(value[i].data, type[n].key.data) == 0) {
1667 old = type[n].value;
1668 type[n].value = content_type;
1669
1670 ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
1671 "duplicate extention \"%V\", "
1672 "content type: \"%V\", "
1673 "old content type: \"%V\"",
1674 &value[i], content_type, old);
1675 continue;
1676 }
1677 }
1678
1679
1680 type = ngx_array_push(lcf->types);
1666 if (type == NULL) { 1681 if (type == NULL) {
1667 return NGX_CONF_ERROR; 1682 return NGX_CONF_ERROR;
1668 } 1683 }
1669 1684
1670 type->exten = value[i]; 1685 type->key = value[i];
1671 type->type = value[0]; 1686 type->key_hash = ngx_hash_key(value[i].data, value[i].len);
1687 type->value = content_type;
1672 } 1688 }
1673 1689
1674 return NGX_CONF_OK; 1690 return NGX_CONF_OK;
1675 } 1691 }
1676 1692
1903 lcf->lingering_timeout = NGX_CONF_UNSET_MSEC; 1919 lcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
1904 lcf->reset_timedout_connection = NGX_CONF_UNSET; 1920 lcf->reset_timedout_connection = NGX_CONF_UNSET;
1905 lcf->port_in_redirect = NGX_CONF_UNSET; 1921 lcf->port_in_redirect = NGX_CONF_UNSET;
1906 lcf->msie_padding = NGX_CONF_UNSET; 1922 lcf->msie_padding = NGX_CONF_UNSET;
1907 lcf->log_not_found = NGX_CONF_UNSET; 1923 lcf->log_not_found = NGX_CONF_UNSET;
1924 lcf->types_hash_max_size = NGX_CONF_UNSET_UINT;
1925 lcf->types_hash_bucket_size = NGX_CONF_UNSET_UINT;
1908 1926
1909 return lcf; 1927 return lcf;
1910 } 1928 }
1911 1929
1912 1930
1913 static ngx_http_type_t ngx_http_core_default_types[] = { 1931 static ngx_str_t ngx_http_core_text_html_type = ngx_string("text/html");
1914 { ngx_string("html"), ngx_string("text/html") }, 1932 static ngx_str_t ngx_http_core_image_gif_type = ngx_string("image/gif");
1915 { ngx_string("gif"), ngx_string("image/gif") }, 1933 static ngx_str_t ngx_http_core_image_jpeg_type = ngx_string("image/jpeg");
1916 { ngx_string("jpg"), ngx_string("image/jpeg") }, 1934
1917 { ngx_null_string, ngx_null_string } 1935 static ngx_hash_key_t ngx_http_core_default_types[] = {
1936 { ngx_string("html"), 0, &ngx_http_core_text_html_type },
1937 { ngx_string("gif"), 0, &ngx_http_core_image_gif_type },
1938 { ngx_string("jpg"), 0, &ngx_http_core_image_jpeg_type },
1939 { ngx_null_string, 0, NULL }
1918 }; 1940 };
1919 1941
1920 1942
1921 static char * 1943 static char *
1922 ngx_http_core_merge_loc_conf(ngx_conf_t *cf, 1944 ngx_http_core_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
1923 void *parent, void *child)
1924 { 1945 {
1925 ngx_http_core_loc_conf_t *prev = parent; 1946 ngx_http_core_loc_conf_t *prev = parent;
1926 ngx_http_core_loc_conf_t *conf = child; 1947 ngx_http_core_loc_conf_t *conf = child;
1927 1948
1928 uint32_t key;
1929 ngx_uint_t i; 1949 ngx_uint_t i;
1930 ngx_http_type_t *type; 1950 ngx_hash_key_t *type;
1951 ngx_hash_init_t types_hash;
1931 1952
1932 ngx_conf_merge_str_value(conf->root, prev->root, "html"); 1953 ngx_conf_merge_str_value(conf->root, prev->root, "html");
1933 1954
1934 if (ngx_conf_full_name(cf->cycle, &conf->root) == NGX_ERROR) { 1955 if (ngx_conf_full_name(cf->cycle, &conf->root) == NGX_ERROR) {
1935 return NGX_CONF_ERROR; 1956 return NGX_CONF_ERROR;
1937 1958
1938 if (conf->post_action.data == NULL) { 1959 if (conf->post_action.data == NULL) {
1939 conf->post_action = prev->post_action; 1960 conf->post_action = prev->post_action;
1940 } 1961 }
1941 1962
1963 ngx_conf_merge_unsigned_value(conf->types_hash_max_size,
1964 prev->types_hash_max_size, 512);
1965
1966 ngx_conf_merge_unsigned_value(conf->types_hash_bucket_size,
1967 prev->types_hash_bucket_size,
1968 ngx_cacheline_size);
1969
1970 conf->types_hash_bucket_size = ngx_align(conf->types_hash_bucket_size,
1971 ngx_cacheline_size);
1972
1973 /*
1974 * the special handling the "types" directive in the "http" section
1975 * to inherit the http's conf->types_hash to all servers
1976 */
1977
1978 if (prev->types && prev->types_hash.buckets == NULL) {
1979
1980 types_hash.hash = &prev->types_hash;
1981 types_hash.key = ngx_hash_key_lc;
1982 types_hash.max_size = conf->types_hash_max_size;
1983 types_hash.bucket_size = conf->types_hash_bucket_size;
1984 types_hash.name = "mime_types";
1985 types_hash.pool = cf->pool;
1986 types_hash.temp_pool = NULL;
1987
1988 if (ngx_hash_init(&types_hash, prev->types->elts, prev->types->nelts)
1989 != NGX_OK)
1990 {
1991 return NGX_CONF_ERROR;
1992 }
1993 }
1994
1942 if (conf->types == NULL) { 1995 if (conf->types == NULL) {
1943 if (prev->types) { 1996 conf->types = prev->types;
1944 conf->types = prev->types; 1997 conf->types_hash = prev->types_hash;
1945 1998 }
1946 } else { 1999
1947 conf->types = ngx_palloc(cf->pool, NGX_HTTP_TYPES_HASH_PRIME 2000 if (conf->types == NULL) {
1948 * sizeof(ngx_array_t)); 2001 conf->types = ngx_array_create(cf->pool, 4, sizeof(ngx_hash_key_t));
1949 if (conf->types == NULL) { 2002 if (conf->types == NULL) {
2003 return NGX_CONF_ERROR;
2004 }
2005
2006 for (i = 0; ngx_http_core_default_types[i].key.len; i++) {
2007 type = ngx_array_push(conf->types);
2008 if (type == NULL) {
1950 return NGX_CONF_ERROR; 2009 return NGX_CONF_ERROR;
1951 } 2010 }
1952 2011
1953 for (i = 0; i < NGX_HTTP_TYPES_HASH_PRIME; i++) { 2012 type->key = ngx_http_core_default_types[i].key;
1954 if (ngx_array_init(&conf->types[i], cf->pool, 4, 2013 type->key_hash =
1955 sizeof(ngx_http_type_t)) == NGX_ERROR) 2014 ngx_hash_key_lc(ngx_http_core_default_types[i].key.data,
1956 { 2015 ngx_http_core_default_types[i].key.len);
1957 return NGX_CONF_ERROR; 2016 type->value = ngx_http_core_default_types[i].value;
1958 } 2017 }
1959 } 2018 }
1960 2019
1961 for (i = 0; ngx_http_core_default_types[i].exten.len; i++) { 2020 if (conf->types_hash.buckets == NULL) {
1962 ngx_http_types_hash_key(key, 2021
1963 ngx_http_core_default_types[i].exten); 2022 types_hash.hash = &conf->types_hash;
1964 2023 types_hash.key = ngx_hash_key_lc;
1965 type = ngx_array_push(&conf->types[key]); 2024 types_hash.max_size = conf->types_hash_max_size;
1966 if (type == NULL) { 2025 types_hash.bucket_size = conf->types_hash_bucket_size;
1967 return NGX_CONF_ERROR; 2026 types_hash.name = "mime_types";
1968 } 2027 types_hash.pool = cf->pool;
1969 2028 types_hash.temp_pool = NULL;
1970 *type = ngx_http_core_default_types[i]; 2029
1971 } 2030 if (ngx_hash_init(&types_hash, conf->types->elts, conf->types->nelts)
2031 != NGX_OK)
2032 {
2033 return NGX_CONF_ERROR;
1972 } 2034 }
1973 } 2035 }
1974 2036
1975 if (conf->err_log == NULL) { 2037 if (conf->err_log == NULL) {
1976 if (prev->err_log) { 2038 if (prev->err_log) {
2113 } 2175 }
2114 2176
2115 if (ngx_strcmp(value[2].data, "default") == 0) { 2177 if (ngx_strcmp(value[2].data, "default") == 0) {
2116 ls->conf.default_server = 1; 2178 ls->conf.default_server = 1;
2117 n = 3; 2179 n = 3;
2180
2118 } else { 2181 } else {
2119 n = 2; 2182 n = 2;
2120 } 2183 }
2121 2184
2122 for ( /* void */ ; n < cf->args->nelts; n++) { 2185 for ( /* void */ ; n < cf->args->nelts; n++) {