comparison src/http/ngx_http_core_module.c @ 632:5b73504dd4ba NGINX_1_1_0

nginx 1.1.0 *) Feature: cache loader run time decrease. *) Feature: "loader_files", "loader_sleep", and "loader_threshold" options of the "proxy/fastcgi/scgi/uwsgi_cache_path" directives. *) 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. Thanks to Maxim Dounin. *) Bugfix: in closing connection for pipelined requests. Thanks to Maxim Dounin. *) 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. Thanks to Maxim Dounin. *) Bugfix: memory leaks when a "proxy_pass" directive contains variables and proxies to an HTTPS backend. Thanks to Maxim Dounin. *) Bugfix: in parameter validaiton of a "proxy_pass" directive with variables. Thanks to Lanshun Zhou. *) Bugfix: SSL did not work on QNX. Thanks to Maxim Dounin. *) Bugfix: SSL modules could not be built by gcc 4.6 without --with-debug option.
author Igor Sysoev <http://sysoev.ru>
date Mon, 01 Aug 2011 00:00:00 +0400
parents 8dc007eddbcf
children 23ef0645ea57
comparison
equal deleted inserted replaced
631:9b978fa3cd33 632:5b73504dd4ba
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);
73 static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd, 74 static char *ngx_http_gzip_disable(ngx_conf_t *cf, ngx_command_t *cmd,
74 void *conf); 75 void *conf);
75 #endif 76 #endif
76 77
77 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data); 78 static char *ngx_http_core_lowat_check(ngx_conf_t *cf, void *post, void *data);
119 120
120 121
121 static ngx_conf_enum_t ngx_http_core_satisfy[] = { 122 static ngx_conf_enum_t ngx_http_core_satisfy[] = {
122 { ngx_string("all"), NGX_HTTP_SATISFY_ALL }, 123 { ngx_string("all"), NGX_HTTP_SATISFY_ALL },
123 { ngx_string("any"), NGX_HTTP_SATISFY_ANY }, 124 { ngx_string("any"), NGX_HTTP_SATISFY_ANY },
125 { ngx_null_string, 0 }
126 };
127
128
129 static ngx_conf_enum_t ngx_http_core_lingering_close[] = {
130 { ngx_string("off"), NGX_HTTP_LINGERING_OFF },
131 { ngx_string("on"), NGX_HTTP_LINGERING_ON },
132 { ngx_string("always"), NGX_HTTP_LINGERING_ALWAYS },
124 { ngx_null_string, 0 } 133 { ngx_null_string, 0 }
125 }; 134 };
126 135
127 136
128 static ngx_conf_enum_t ngx_http_core_if_modified_since[] = { 137 static ngx_conf_enum_t ngx_http_core_if_modified_since[] = {
527 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS, 536 NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
528 ngx_http_core_internal, 537 ngx_http_core_internal,
529 NGX_HTTP_LOC_CONF_OFFSET, 538 NGX_HTTP_LOC_CONF_OFFSET,
530 0, 539 0,
531 NULL }, 540 NULL },
541
542 { ngx_string("lingering_close"),
543 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
544 ngx_conf_set_enum_slot,
545 NGX_HTTP_LOC_CONF_OFFSET,
546 offsetof(ngx_http_core_loc_conf_t, lingering_close),
547 &ngx_http_core_lingering_close },
532 548
533 { ngx_string("lingering_time"), 549 { ngx_string("lingering_time"),
534 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, 550 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
535 ngx_conf_set_msec_slot, 551 ngx_conf_set_msec_slot,
536 NGX_HTTP_LOC_CONF_OFFSET, 552 NGX_HTTP_LOC_CONF_OFFSET,
2014 ngx_http_gzip_ok(ngx_http_request_t *r) 2030 ngx_http_gzip_ok(ngx_http_request_t *r)
2015 { 2031 {
2016 time_t date, expires; 2032 time_t date, expires;
2017 ngx_uint_t p; 2033 ngx_uint_t p;
2018 ngx_array_t *cc; 2034 ngx_array_t *cc;
2019 ngx_table_elt_t *e, *d; 2035 ngx_table_elt_t *e, *d, *ae;
2020 ngx_http_core_loc_conf_t *clcf; 2036 ngx_http_core_loc_conf_t *clcf;
2021 2037
2022 r->gzip_tested = 1; 2038 r->gzip_tested = 1;
2023 2039
2024 if (r != r->main 2040 if (r != r->main) {
2025 || r->headers_in.accept_encoding == NULL 2041 return NGX_DECLINED;
2026 || ngx_strcasestrn(r->headers_in.accept_encoding->value.data, 2042 }
2027 "gzip", 4 - 1) 2043
2028 == NULL 2044 ae = r->headers_in.accept_encoding;
2029 2045 if (ae == NULL) {
2030 /* 2046 return NGX_DECLINED;
2031 * if the URL (without the "http://" prefix) is longer than 253 bytes, 2047 }
2032 * then MSIE 4.x can not handle the compressed stream - it waits 2048
2033 * too long, hangs up or crashes 2049 if (ae->value.len < sizeof("gzip") - 1) {
2034 */ 2050 return NGX_DECLINED;
2035 2051 }
2036 || (r->headers_in.msie4 && r->unparsed_uri.len > 200)) 2052
2053 /*
2054 * test first for the most common case "gzip,...":
2055 * MSIE: "gzip, deflate"
2056 * Firefox: "gzip,deflate"
2057 * Chrome: "gzip,deflate,sdch"
2058 * Safari: "gzip, deflate"
2059 * Opera: "gzip, deflate"
2060 */
2061
2062 if (ngx_memcmp(ae->value.data, "gzip,", 5) != 0
2063 && ngx_http_gzip_accept_encoding(&ae->value) != NGX_OK)
2037 { 2064 {
2038 return NGX_DECLINED; 2065 return NGX_DECLINED;
2039 } 2066 }
2040 2067
2041 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); 2068 clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
2155 #endif 2182 #endif
2156 2183
2157 r->gzip_ok = 1; 2184 r->gzip_ok = 1;
2158 2185
2159 return NGX_OK; 2186 return NGX_OK;
2187 }
2188
2189
2190 /*
2191 * gzip is enabled for the following quantities:
2192 * "gzip; q=0.001" ... "gzip; q=0.999", "gzip; q=1"
2193 * gzip is disabled for the following quantities:
2194 * "gzip; q=0" ... "gzip; q=0.000", and for any invalid cases
2195 */
2196
2197 static ngx_int_t
2198 ngx_http_gzip_accept_encoding(ngx_str_t *ae)
2199 {
2200 u_char c, *p, *start, *last;
2201 ngx_uint_t n, q;
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 c = *p++;
2259
2260 if (c == '1') {
2261 if (p == last || *p == ',' || *p == ' ') {
2262 return NGX_OK;
2263 }
2264 return NGX_DECLINED;
2265 }
2266
2267 if (c != '0') {
2268 return NGX_DECLINED;
2269 }
2270
2271 if (p == last) {
2272 return NGX_DECLINED;
2273 }
2274
2275 if (*p++ != '.') {
2276 return NGX_DECLINED;
2277 }
2278
2279 n = 0;
2280 q = 0;
2281
2282 while (p < last) {
2283 c = *p++;
2284
2285 if (c == ',') {
2286 break;
2287 }
2288
2289 if (c >= '1' && c <= '9') {
2290 n++;
2291 q++;
2292 continue;
2293 }
2294
2295 if (c == '0') {
2296 n++;
2297 continue;
2298 }
2299
2300 return NGX_DECLINED;
2301 }
2302
2303 if (n < 4 && q != 0) {
2304 return NGX_OK;
2305 }
2306
2307 return NGX_DECLINED;
2160 } 2308 }
2161 2309
2162 #endif 2310 #endif
2163 2311
2164 2312
3115 clcf->limit_rate = NGX_CONF_UNSET_SIZE; 3263 clcf->limit_rate = NGX_CONF_UNSET_SIZE;
3116 clcf->limit_rate_after = NGX_CONF_UNSET_SIZE; 3264 clcf->limit_rate_after = NGX_CONF_UNSET_SIZE;
3117 clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC; 3265 clcf->keepalive_timeout = NGX_CONF_UNSET_MSEC;
3118 clcf->keepalive_header = NGX_CONF_UNSET; 3266 clcf->keepalive_header = NGX_CONF_UNSET;
3119 clcf->keepalive_requests = NGX_CONF_UNSET_UINT; 3267 clcf->keepalive_requests = NGX_CONF_UNSET_UINT;
3268 clcf->lingering_close = NGX_CONF_UNSET_UINT;
3120 clcf->lingering_time = NGX_CONF_UNSET_MSEC; 3269 clcf->lingering_time = NGX_CONF_UNSET_MSEC;
3121 clcf->lingering_timeout = NGX_CONF_UNSET_MSEC; 3270 clcf->lingering_timeout = NGX_CONF_UNSET_MSEC;
3122 clcf->resolver_timeout = NGX_CONF_UNSET_MSEC; 3271 clcf->resolver_timeout = NGX_CONF_UNSET_MSEC;
3123 clcf->reset_timedout_connection = NGX_CONF_UNSET; 3272 clcf->reset_timedout_connection = NGX_CONF_UNSET;
3124 clcf->server_name_in_redirect = NGX_CONF_UNSET; 3273 clcf->server_name_in_redirect = NGX_CONF_UNSET;
3331 prev->keepalive_timeout, 75000); 3480 prev->keepalive_timeout, 75000);
3332 ngx_conf_merge_sec_value(conf->keepalive_header, 3481 ngx_conf_merge_sec_value(conf->keepalive_header,
3333 prev->keepalive_header, 0); 3482 prev->keepalive_header, 0);
3334 ngx_conf_merge_uint_value(conf->keepalive_requests, 3483 ngx_conf_merge_uint_value(conf->keepalive_requests,
3335 prev->keepalive_requests, 100); 3484 prev->keepalive_requests, 100);
3485 ngx_conf_merge_msec_value(conf->lingering_close,
3486 prev->lingering_close, NGX_HTTP_LINGERING_ON);
3336 ngx_conf_merge_msec_value(conf->lingering_time, 3487 ngx_conf_merge_msec_value(conf->lingering_time,
3337 prev->lingering_time, 30000); 3488 prev->lingering_time, 30000);
3338 ngx_conf_merge_msec_value(conf->lingering_timeout, 3489 ngx_conf_merge_msec_value(conf->lingering_timeout,
3339 prev->lingering_timeout, 5000); 3490 prev->lingering_timeout, 5000);
3340 ngx_conf_merge_msec_value(conf->resolver_timeout, 3491 ngx_conf_merge_msec_value(conf->resolver_timeout,