comparison src/http/ngx_http_core_module.c @ 632:65fd8be45530 NGINX_1_0_6

nginx 1.0.6 *) Feature: cache loader run time decrease. *) Feature: loading time decrease of configuration with large number of HTTPS sites. *) Feature: now nginx supports ECDHE key exchange ciphers. Thanks to Adrian Kotelba. *) Feature: the "lingering_close" directive. *) Feature: now shared zones and caches use POSIX semaphores on Solaris. Thanks to Den Ivanov. *) Bugfix: nginx could not be built on Linux 3.0. *) Bugfix: a segmentation fault might occur in a worker process if "fastcgi/scgi/uwsgi_param" directives were used with values starting with "HTTP_"; the bug had appeared in 0.8.40. *) Bugfix: in closing connection for pipelined requests. *) Bugfix: nginx did not disable gzipping if client sent "gzip;q=0" in "Accept-Encoding" request header line. *) Bugfix: in timeout in unbuffered proxied mode. *) Bugfix: memory leaks when a "proxy_pass" directive contains variables and proxies to an HTTPS backend. *) Bugfix: in parameter validaiton of a "proxy_pass" directive with variables. Thanks to Lanshun Zhou. *) Bugfix: SSL did not work on QNX. *) Bugfix: SSL modules could not be built by gcc 4.6 without --with-debug option.
author Igor Sysoev <http://sysoev.ru>
date Fri, 29 Jul 2011 00:00:00 +0400
parents 8dc007eddbcf
children 0d6525917227
comparison
equal deleted inserted replaced
631:9b978fa3cd33 632:65fd8be45530
68 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd, 68 static char *ngx_http_core_internal(ngx_conf_t *cf, ngx_command_t *cmd,
69 void *conf); 69 void *conf);
70 static char *ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, 70 static char *ngx_http_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
71 void *conf); 71 void *conf);
72 #if (NGX_HTTP_GZIP) 72 #if (NGX_HTTP_GZIP)
73 static ngx_int_t ngx_http_gzip_accept_encoding(ngx_str_t *ae);
74 static ngx_uint_t ngx_http_gzip_quantity(u_char *p, u_char *last);
73 static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, 75 static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd,
74 void *conf); 76 void *conf);
75 #endif 77 #endif
76 78
77 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data); 79 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
119 121
120 122
121 static ngx_conf_enum_t ngx_http_core_satisfy[] = { 123 static ngx_conf_enum_t ngx_http_core_satisfy[] = {
122 { ngx_string("all"), NGX_HTTP_SATISFY_ALL }, 124 { ngx_string("all"), NGX_HTTP_SATISFY_ALL },
123 { ngx_string("any"), NGX_HTTP_SATISFY_ANY }, 125 { ngx_string("any"), NGX_HTTP_SATISFY_ANY },
126 { ngx_null_string, 0 }
127 };
128
129
130 static ngx_conf_enum_t ngx_http_core_lingering_close[] = {
131 { ngx_string("off"), NGX_HTTP_LINGERING_OFF },
132 { ngx_string("on"), NGX_HTTP_LINGERING_ON },
133 { ngx_string("always"), NGX_HTTP_LINGERING_ALWAYS },
124 { ngx_null_string, 0 } 134 { ngx_null_string, 0 }
125 }; 135 };
126 136
127 137
128 static ngx_conf_enum_t ngx_http_core_if_modified_since[] = { 138 static ngx_conf_enum_t ngx_http_core_if_modified_since[] = {
527 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS, 537 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
528 ngx_http_core_internal, 538 ngx_http_core_internal,
529 NGX_HTTP_LOC_CONF_OFFSET, 539 NGX_HTTP_LOC_CONF_OFFSET,
530 0, 540 0,
531 NULL }, 541 NULL },
542
543 { ngx_string("lingering_close"),
544 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
545 ngx_conf_set_enum_slot,
546 NGX_HTTP_LOC_CONF_OFFSET,
547 offsetof(ngx_http_core_loc_conf_t, lingering_close),
548 &ngx_http_core_lingering_close },
532 549
533 { ngx_string("lingering_time"), 550 { ngx_string("lingering_time"),
534 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 551 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
535 ngx_conf_set_msec_slot, 552 ngx_conf_set_msec_slot,
536 NGX_HTTP_LOC_CONF_OFFSET, 553 NGX_HTTP_LOC_CONF_OFFSET,
2014 ngx_http_gzip_ok(ngx_http_request_t *r) 2031 ngx_http_gzip_ok(ngx_http_request_t *r)
2015 { 2032 {
2016 time_t date, expires; 2033 time_t date, expires;
2017 ngx_uint_t p; 2034 ngx_uint_t p;
2018 ngx_array_t *cc; 2035 ngx_array_t *cc;
2019 ngx_table_elt_t *e, *d; 2036 ngx_table_elt_t *e, *d, *ae;
2020 ngx_http_core_loc_conf_t *clcf; 2037 ngx_http_core_loc_conf_t *clcf;
2021 2038
2022 r->gzip_tested = 1; 2039 r->gzip_tested = 1;
2023 2040
2024 if (r != r->main 2041 if (r != r->main) {
2025 || r->headers_in.accept_encoding == NULL 2042 return NGX_DECLINED;
2026 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data, 2043 }
2027 "gzip", 4 - 1) 2044
2028 == NULL 2045 ae = r->headers_in.accept_encoding;
2029 2046 if (ae == NULL) {
2030 /* 2047 return NGX_DECLINED;
2031 * if the URL (without the "http://" prefix) is longer than 253 bytes, 2048 }
2032 * then MSIE 4.x can not handle the compressed stream - it waits 2049
2033 * too long, hangs up or crashes 2050 if (ae->value.len < sizeof("gzip") - 1) {
2034 */ 2051 return NGX_DECLINED;
2035 2052 }
2036 || (r->headers_in.msie4 && r->unparsed_uri.len > 200)) 2053
2054 /*
2055 * test first for the most common case "gzip,...":
2056 * MSIE: "gzip, deflate"
2057 * Firefox: "gzip,deflate"
2058 * Chrome: "gzip,deflate,sdch"
2059 * Safari: "gzip, deflate"
2060 * Opera: "gzip, deflate"
2061 */
2062
2063 if (ngx_memcmp(ae->value.data, "gzip,", 5) != 0
2064 && ngx_http_gzip_accept_encoding(&ae->value) != NGX_OK)
2037 { 2065 {
2038 return NGX_DECLINED; 2066 return NGX_DECLINED;
2039 } 2067 }
2040 2068
2041 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 2069 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
2155 #endif 2183 #endif
2156 2184
2157 r->gzip_ok = 1; 2185 r->gzip_ok = 1;
2158 2186
2159 return NGX_OK; 2187 return NGX_OK;
2188 }
2189
2190
2191 /*
2192 * gzip is enabled for the following quantities:
2193 * "gzip; q=0.001" ... "gzip; q=1.000"
2194 * gzip is disabled for the following quantities:
2195 * "gzip; q=0" ... "gzip; q=0.000", and for any invalid cases
2196 */
2197
2198 static ngx_int_t
2199 ngx_http_gzip_accept_encoding(ngx_str_t *ae)
2200 {
2201 u_char *p, *start, *last;
2202
2203 start = ae->data;
2204 last = start + ae->len;
2205
2206 for ( ;; ) {
2207 p = ngx_strcasestrn(start, "gzip", 4 - 1);
2208 if (p == NULL) {
2209 return NGX_DECLINED;
2210 }
2211
2212 if (p == start || (*(p - 1) == ',' || *(p - 1) == ' ')) {
2213 break;
2214 }
2215
2216 start = p + 4;
2217 }
2218
2219 p += 4;
2220
2221 while (p < last) {
2222 switch(*p++) {
2223 case ',':
2224 return NGX_OK;
2225 case ';':
2226 goto quantity;
2227 case ' ':
2228 continue;
2229 default:
2230 return NGX_DECLINED;
2231 }
2232 }
2233
2234 return NGX_OK;
2235
2236 quantity:
2237
2238 while (p < last) {
2239 switch(*p++) {
2240 case 'q':
2241 case 'Q':
2242 goto equal;
2243 case ' ':
2244 continue;
2245 default:
2246 return NGX_DECLINED;
2247 }
2248 }
2249
2250 return NGX_OK;
2251
2252 equal:
2253
2254 if (p + 2 > last || *p++ != '=') {
2255 return NGX_DECLINED;
2256 }
2257
2258 if (ngx_http_gzip_quantity(p, last) == 0) {
2259 return NGX_DECLINED;
2260 }
2261
2262 return NGX_OK;
2263 }
2264
2265
2266 ngx_uint_t
2267 ngx_http_gzip_quantity(u_char *p, u_char *last)
2268 {
2269 u_char c;
2270 ngx_uint_t n, q;
2271
2272 c = *p++;
2273
2274 if (c != '0' && c != '1') {
2275 return 0;
2276 }
2277
2278 q = (c - '0') * 100;
2279
2280 if (p == last) {
2281 return q;
2282 }
2283
2284 c = *p++;
2285
2286 if (c == ',' || c == ' ') {
2287 return q;
2288 }
2289
2290 if (c != '.') {
2291 return 0;
2292 }
2293
2294 n = 0;
2295
2296 while (p < last) {
2297 c = *p++;
2298
2299 if (c == ',' || c == ' ') {
2300 break;
2301 }
2302
2303 if (c >= '0' && c <= '9') {
2304 q += c - '0';
2305 n++;
2306 continue;
2307 }
2308
2309 return 0;
2310 }
2311
2312 if (q > 100 || n > 3) {
2313 return 0;
2314 }
2315
2316 return q;
2160 } 2317 }
2161 2318
2162 #endif 2319 #endif
2163 2320
2164 2321
3115 clcf->limit_rate = NGX_CONF_UNSET_SIZE; 3272 clcf->limit_rate = NGX_CONF_UNSET_SIZE;
3116 clcf->limit_rate_after = NGX_CONF_UNSET_SIZE; 3273 clcf->limit_rate_after = NGX_CONF_UNSET_SIZE;
3117 clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC; 3274 clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
3118 clcf->keepalive_header = NGX_CONF_UNSET; 3275 clcf->keepalive_header = NGX_CONF_UNSET;
3119 clcf->keepalive_requests = NGX_CONF_UNSET_UINT; 3276 clcf->keepalive_requests = NGX_CONF_UNSET_UINT;
3277 clcf->lingering_close = NGX_CONF_UNSET_UINT;
3120 clcf->lingering_time = NGX_CONF_UNSET_MSEC; 3278 clcf->lingering_time = NGX_CONF_UNSET_MSEC;
3121 clcf->lingering_timeout = NGX_CONF_UNSET_MSEC; 3279 clcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
3122 clcf->resolver_timeout = NGX_CONF_UNSET_MSEC; 3280 clcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
3123 clcf->reset_timedout_connection = NGX_CONF_UNSET; 3281 clcf->reset_timedout_connection = NGX_CONF_UNSET;
3124 clcf->server_name_in_redirect = NGX_CONF_UNSET; 3282 clcf->server_name_in_redirect = NGX_CONF_UNSET;
3331 prev->keepalive_timeout, 75000); 3489 prev->keepalive_timeout, 75000);
3332 ngx_conf_merge_sec_value(conf->keepalive_header, 3490 ngx_conf_merge_sec_value(conf->keepalive_header,
3333 prev->keepalive_header, 0); 3491 prev->keepalive_header, 0);
3334 ngx_conf_merge_uint_value(conf->keepalive_requests, 3492 ngx_conf_merge_uint_value(conf->keepalive_requests,
3335 prev->keepalive_requests, 100); 3493 prev->keepalive_requests, 100);
3494 ngx_conf_merge_uint_value(conf->lingering_close,
3495 prev->lingering_close, NGX_HTTP_LINGERING_ON);
3336 ngx_conf_merge_msec_value(conf->lingering_time, 3496 ngx_conf_merge_msec_value(conf->lingering_time,
3337 prev->lingering_time, 30000); 3497 prev->lingering_time, 30000);
3338 ngx_conf_merge_msec_value(conf->lingering_timeout, 3498 ngx_conf_merge_msec_value(conf->lingering_timeout,
3339 prev->lingering_timeout, 5000); 3499 prev->lingering_timeout, 5000);
3340 ngx_conf_merge_msec_value(conf->resolver_timeout, 3500 ngx_conf_merge_msec_value(conf->resolver_timeout,