Mercurial > hg > nginx-vendor-current
comparison src/http/modules/ngx_http_fastcgi_module.c @ 648:f200748c0ac8 NGINX_1_1_8
nginx 1.1.8
*) Change: the ngx_http_limit_zone_module was renamed to the
ngx_http_limit_conn_module.
*) Change: the "limit_zone" directive was superseded by the
"limit_conn_zone" directive with a new syntax.
*) Feature: support for multiple "limit_conn" limits on the same level.
*) Feature: the "image_filter_sharpen" directive.
*) Bugfix: a segmentation fault might occur in a worker process if
resolver got a big DNS response.
Thanks to Ben Hawkes.
*) Bugfix: in cache key calculation if internal MD5 implementation was
used; the bug had appeared in 1.0.4.
*) Bugfix: the "If-Modified-Since", "If-Range", etc. client request
header lines might be passed to backend while caching; or not passed
without caching if caching was enabled in another part of the
configuration.
*) Bugfix: the module ngx_http_mp4_module sent incorrect
"Content-Length" response header line if the "start" argument was
used.
Thanks to Piotr Sikora.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 14 Nov 2011 00:00:00 +0400 |
parents | eb208e0cf44d |
children | 753f505670e0 |
comparison
equal
deleted
inserted
replaced
647:bec017127243 | 648:f200748c0ac8 |
---|---|
145 | 145 |
146 static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf); | 146 static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf); |
147 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); | 147 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); |
148 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, | 148 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, |
149 void *parent, void *child); | 149 void *parent, void *child); |
150 static ngx_int_t ngx_http_fastcgi_merge_params(ngx_conf_t *cf, | |
151 ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev); | |
152 | |
150 static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, | 153 static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, |
151 ngx_http_variable_value_t *v, uintptr_t data); | 154 ngx_http_variable_value_t *v, uintptr_t data); |
152 static ngx_int_t ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r, | 155 static ngx_int_t ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r, |
153 ngx_http_variable_value_t *v, uintptr_t data); | 156 ngx_http_variable_value_t *v, uintptr_t data); |
154 static ngx_http_fastcgi_ctx_t *ngx_http_fastcgi_split(ngx_http_request_t *r, | 157 static ngx_http_fastcgi_ctx_t *ngx_http_fastcgi_split(ngx_http_request_t *r, |
434 NGX_HTTP_LOC_CONF_OFFSET, | 437 NGX_HTTP_LOC_CONF_OFFSET, |
435 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.ignore_headers), | 438 offsetof(ngx_http_fastcgi_loc_conf_t, upstream.ignore_headers), |
436 &ngx_http_upstream_ignore_headers_masks }, | 439 &ngx_http_upstream_ignore_headers_masks }, |
437 | 440 |
438 { ngx_string("fastcgi_catch_stderr"), | 441 { ngx_string("fastcgi_catch_stderr"), |
439 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG, | 442 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1, |
440 ngx_conf_set_str_array_slot, | 443 ngx_conf_set_str_array_slot, |
441 NGX_HTTP_LOC_CONF_OFFSET, | 444 NGX_HTTP_LOC_CONF_OFFSET, |
442 offsetof(ngx_http_fastcgi_loc_conf_t, catch_stderr), | 445 offsetof(ngx_http_fastcgi_loc_conf_t, catch_stderr), |
443 NULL }, | 446 NULL }, |
444 | 447 |
2083 ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) | 2086 ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) |
2084 { | 2087 { |
2085 ngx_http_fastcgi_loc_conf_t *prev = parent; | 2088 ngx_http_fastcgi_loc_conf_t *prev = parent; |
2086 ngx_http_fastcgi_loc_conf_t *conf = child; | 2089 ngx_http_fastcgi_loc_conf_t *conf = child; |
2087 | 2090 |
2088 u_char *p; | |
2089 size_t size; | 2091 size_t size; |
2090 uintptr_t *code; | |
2091 ngx_uint_t i; | |
2092 ngx_array_t headers_names; | |
2093 ngx_keyval_t *src; | |
2094 ngx_hash_key_t *hk; | |
2095 ngx_hash_init_t hash; | 2092 ngx_hash_init_t hash; |
2096 ngx_http_core_loc_conf_t *clcf; | 2093 ngx_http_core_loc_conf_t *clcf; |
2097 ngx_http_script_compile_t sc; | |
2098 ngx_http_script_copy_code_t *copy; | |
2099 | 2094 |
2100 if (conf->upstream.store != 0) { | 2095 if (conf->upstream.store != 0) { |
2101 ngx_conf_merge_value(conf->upstream.store, | 2096 ngx_conf_merge_value(conf->upstream.store, |
2102 prev->upstream.store, 0); | 2097 prev->upstream.store, 0); |
2103 | 2098 |
2353 conf->split_regex = prev->split_regex; | 2348 conf->split_regex = prev->split_regex; |
2354 conf->split_name = prev->split_name; | 2349 conf->split_name = prev->split_name; |
2355 } | 2350 } |
2356 #endif | 2351 #endif |
2357 | 2352 |
2353 if (ngx_http_fastcgi_merge_params(cf, conf, prev) != NGX_OK) { | |
2354 return NGX_CONF_ERROR; | |
2355 } | |
2356 | |
2357 return NGX_CONF_OK; | |
2358 } | |
2359 | |
2360 | |
2361 static ngx_int_t | |
2362 ngx_http_fastcgi_merge_params(ngx_conf_t *cf, | |
2363 ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev) | |
2364 { | |
2365 u_char *p; | |
2366 size_t size; | |
2367 uintptr_t *code; | |
2368 ngx_uint_t i, nsrc; | |
2369 ngx_array_t headers_names; | |
2370 #if (NGX_HTTP_CACHE) | |
2371 ngx_array_t params_merged; | |
2372 #endif | |
2373 ngx_keyval_t *src; | |
2374 ngx_hash_key_t *hk; | |
2375 ngx_hash_init_t hash; | |
2376 ngx_http_script_compile_t sc; | |
2377 ngx_http_script_copy_code_t *copy; | |
2378 | |
2358 if (conf->params_source == NULL) { | 2379 if (conf->params_source == NULL) { |
2359 conf->flushes = prev->flushes; | |
2360 conf->params_len = prev->params_len; | |
2361 conf->params = prev->params; | |
2362 conf->params_source = prev->params_source; | 2380 conf->params_source = prev->params_source; |
2363 conf->headers_hash = prev->headers_hash; | 2381 |
2364 | 2382 if (prev->headers_hash.buckets |
2365 #if (NGX_HTTP_CACHE) | 2383 #if (NGX_HTTP_CACHE) |
2366 | 2384 && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL)) |
2367 if (conf->params_source == NULL) { | |
2368 | |
2369 if ((conf->upstream.cache == NULL) | |
2370 == (prev->upstream.cache == NULL)) | |
2371 { | |
2372 return NGX_CONF_OK; | |
2373 } | |
2374 | |
2375 /* 6 is a number of ngx_http_fastcgi_cache_headers entries */ | |
2376 conf->params_source = ngx_array_create(cf->pool, 6, | |
2377 sizeof(ngx_keyval_t)); | |
2378 if (conf->params_source == NULL) { | |
2379 return NGX_CONF_ERROR; | |
2380 } | |
2381 } | |
2382 #else | |
2383 | |
2384 if (conf->params_source == NULL) { | |
2385 return NGX_CONF_OK; | |
2386 } | |
2387 | |
2388 #endif | 2385 #endif |
2386 ) | |
2387 { | |
2388 conf->flushes = prev->flushes; | |
2389 conf->params_len = prev->params_len; | |
2390 conf->params = prev->params; | |
2391 conf->headers_hash = prev->headers_hash; | |
2392 conf->header_params = prev->header_params; | |
2393 | |
2394 return NGX_OK; | |
2395 } | |
2396 } | |
2397 | |
2398 if (conf->params_source == NULL | |
2399 #if (NGX_HTTP_CACHE) | |
2400 && (conf->upstream.cache == NULL) | |
2401 #endif | |
2402 ) | |
2403 { | |
2404 conf->headers_hash.buckets = (void *) 1; | |
2405 return NGX_OK; | |
2389 } | 2406 } |
2390 | 2407 |
2391 conf->params_len = ngx_array_create(cf->pool, 64, 1); | 2408 conf->params_len = ngx_array_create(cf->pool, 64, 1); |
2392 if (conf->params_len == NULL) { | 2409 if (conf->params_len == NULL) { |
2393 return NGX_CONF_ERROR; | 2410 return NGX_ERROR; |
2394 } | 2411 } |
2395 | 2412 |
2396 conf->params = ngx_array_create(cf->pool, 512, 1); | 2413 conf->params = ngx_array_create(cf->pool, 512, 1); |
2397 if (conf->params == NULL) { | 2414 if (conf->params == NULL) { |
2398 return NGX_CONF_ERROR; | 2415 return NGX_ERROR; |
2399 } | 2416 } |
2400 | 2417 |
2401 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) | 2418 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) |
2402 != NGX_OK) | 2419 != NGX_OK) |
2403 { | 2420 { |
2404 return NGX_CONF_ERROR; | 2421 return NGX_ERROR; |
2405 } | 2422 } |
2406 | 2423 |
2407 src = conf->params_source->elts; | 2424 if (conf->params_source) { |
2425 src = conf->params_source->elts; | |
2426 nsrc = conf->params_source->nelts; | |
2427 | |
2428 } else { | |
2429 src = NULL; | |
2430 nsrc = 0; | |
2431 } | |
2408 | 2432 |
2409 #if (NGX_HTTP_CACHE) | 2433 #if (NGX_HTTP_CACHE) |
2410 | 2434 |
2411 if (conf->upstream.cache) { | 2435 if (conf->upstream.cache) { |
2412 ngx_keyval_t *h, *s; | 2436 ngx_keyval_t *h, *s; |
2413 | 2437 |
2414 for (h = ngx_http_fastcgi_cache_headers; h->key.len; h++) { | 2438 if (ngx_array_init(¶ms_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t)) |
2415 | 2439 != NGX_OK) |
2416 for (i = 0; i < conf->params_source->nelts; i++) { | 2440 { |
2441 return NGX_ERROR; | |
2442 } | |
2443 | |
2444 for (i = 0; i < nsrc; i++) { | |
2445 | |
2446 s = ngx_array_push(¶ms_merged); | |
2447 if (s == NULL) { | |
2448 return NGX_ERROR; | |
2449 } | |
2450 | |
2451 *s = src[i]; | |
2452 } | |
2453 | |
2454 h = ngx_http_fastcgi_cache_headers; | |
2455 | |
2456 while (h->key.len) { | |
2457 | |
2458 src = params_merged.elts; | |
2459 nsrc = params_merged.nelts; | |
2460 | |
2461 for (i = 0; i < nsrc; i++) { | |
2417 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) { | 2462 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) { |
2418 goto next; | 2463 goto next; |
2419 } | 2464 } |
2420 } | 2465 } |
2421 | 2466 |
2422 s = ngx_array_push(conf->params_source); | 2467 s = ngx_array_push(¶ms_merged); |
2423 if (s == NULL) { | 2468 if (s == NULL) { |
2424 return NGX_CONF_ERROR; | 2469 return NGX_ERROR; |
2425 } | 2470 } |
2426 | 2471 |
2427 *s = *h; | 2472 *s = *h; |
2428 | 2473 |
2429 src = conf->params_source->elts; | |
2430 | |
2431 next: | 2474 next: |
2432 | 2475 |
2433 h++; | 2476 h++; |
2434 } | 2477 } |
2478 | |
2479 src = params_merged.elts; | |
2480 nsrc = params_merged.nelts; | |
2435 } | 2481 } |
2436 | 2482 |
2437 #endif | 2483 #endif |
2438 | 2484 |
2439 for (i = 0; i < conf->params_source->nelts; i++) { | 2485 for (i = 0; i < nsrc; i++) { |
2440 | 2486 |
2441 if (src[i].key.len > sizeof("HTTP_") - 1 | 2487 if (src[i].key.len > sizeof("HTTP_") - 1 |
2442 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) | 2488 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) |
2443 { | 2489 { |
2444 hk = ngx_array_push(&headers_names); | 2490 hk = ngx_array_push(&headers_names); |
2445 if (hk == NULL) { | 2491 if (hk == NULL) { |
2446 return NGX_CONF_ERROR; | 2492 return NGX_ERROR; |
2447 } | 2493 } |
2448 | 2494 |
2449 hk->key.len = src[i].key.len - 5; | 2495 hk->key.len = src[i].key.len - 5; |
2450 hk->key.data = src[i].key.data + 5; | 2496 hk->key.data = src[i].key.data + 5; |
2451 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len); | 2497 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len); |
2457 } | 2503 } |
2458 | 2504 |
2459 copy = ngx_array_push_n(conf->params_len, | 2505 copy = ngx_array_push_n(conf->params_len, |
2460 sizeof(ngx_http_script_copy_code_t)); | 2506 sizeof(ngx_http_script_copy_code_t)); |
2461 if (copy == NULL) { | 2507 if (copy == NULL) { |
2462 return NGX_CONF_ERROR; | 2508 return NGX_ERROR; |
2463 } | 2509 } |
2464 | 2510 |
2465 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; | 2511 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; |
2466 copy->len = src[i].key.len; | 2512 copy->len = src[i].key.len; |
2467 | 2513 |
2468 | 2514 |
2469 size = (sizeof(ngx_http_script_copy_code_t) | 2515 size = (sizeof(ngx_http_script_copy_code_t) |
2470 + src[i].key.len + sizeof(uintptr_t) - 1) | 2516 + src[i].key.len + sizeof(uintptr_t) - 1) |
2471 & ~(sizeof(uintptr_t) - 1); | 2517 & ~(sizeof(uintptr_t) - 1); |
2472 | 2518 |
2473 copy = ngx_array_push_n(conf->params, size); | 2519 copy = ngx_array_push_n(conf->params, size); |
2474 if (copy == NULL) { | 2520 if (copy == NULL) { |
2475 return NGX_CONF_ERROR; | 2521 return NGX_ERROR; |
2476 } | 2522 } |
2477 | 2523 |
2478 copy->code = ngx_http_script_copy_code; | 2524 copy->code = ngx_http_script_copy_code; |
2479 copy->len = src[i].key.len; | 2525 copy->len = src[i].key.len; |
2480 | 2526 |
2489 sc.flushes = &conf->flushes; | 2535 sc.flushes = &conf->flushes; |
2490 sc.lengths = &conf->params_len; | 2536 sc.lengths = &conf->params_len; |
2491 sc.values = &conf->params; | 2537 sc.values = &conf->params; |
2492 | 2538 |
2493 if (ngx_http_script_compile(&sc) != NGX_OK) { | 2539 if (ngx_http_script_compile(&sc) != NGX_OK) { |
2494 return NGX_CONF_ERROR; | 2540 return NGX_ERROR; |
2495 } | 2541 } |
2496 | 2542 |
2497 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | 2543 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); |
2498 if (code == NULL) { | 2544 if (code == NULL) { |
2499 return NGX_CONF_ERROR; | 2545 return NGX_ERROR; |
2500 } | 2546 } |
2501 | 2547 |
2502 *code = (uintptr_t) NULL; | 2548 *code = (uintptr_t) NULL; |
2503 | 2549 |
2504 | 2550 |
2505 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); | 2551 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); |
2506 if (code == NULL) { | 2552 if (code == NULL) { |
2507 return NGX_CONF_ERROR; | 2553 return NGX_ERROR; |
2508 } | 2554 } |
2509 | 2555 |
2510 *code = (uintptr_t) NULL; | 2556 *code = (uintptr_t) NULL; |
2511 } | 2557 } |
2512 | 2558 |
2513 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | 2559 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); |
2514 if (code == NULL) { | 2560 if (code == NULL) { |
2515 return NGX_CONF_ERROR; | 2561 return NGX_ERROR; |
2516 } | 2562 } |
2517 | 2563 |
2518 *code = (uintptr_t) NULL; | 2564 *code = (uintptr_t) NULL; |
2519 | |
2520 | 2565 |
2521 conf->header_params = headers_names.nelts; | 2566 conf->header_params = headers_names.nelts; |
2522 | 2567 |
2523 hash.hash = &conf->headers_hash; | 2568 hash.hash = &conf->headers_hash; |
2524 hash.key = ngx_hash_key_lc; | 2569 hash.key = ngx_hash_key_lc; |
2526 hash.bucket_size = 64; | 2571 hash.bucket_size = 64; |
2527 hash.name = "fastcgi_params_hash"; | 2572 hash.name = "fastcgi_params_hash"; |
2528 hash.pool = cf->pool; | 2573 hash.pool = cf->pool; |
2529 hash.temp_pool = NULL; | 2574 hash.temp_pool = NULL; |
2530 | 2575 |
2531 if (ngx_hash_init(&hash, headers_names.elts, headers_names.nelts) != NGX_OK) | 2576 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts); |
2532 { | |
2533 return NGX_CONF_ERROR; | |
2534 } | |
2535 | |
2536 return NGX_CONF_OK; | |
2537 } | 2577 } |
2538 | 2578 |
2539 | 2579 |
2540 static ngx_int_t | 2580 static ngx_int_t |
2541 ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, | 2581 ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, |