Mercurial > hg > nginx
comparison src/http/modules/ngx_http_fastcgi_module.c @ 4278:f57229cba7ad
Fixed fastcgi/scgi/uwsgi_param inheritance.
The following problems were fixed:
1. Directive fastcgi_cache affected headers sent to backends in unrelated
servers / locations (see ticket #45).
2. If-Unmodified-Since, If-Match and If-Range headers were sent to backends
if fastcgi_cache was used.
3. Cache-related headers were sent to backends if there were no fastcgi_param
directives and fastcgi_cache was used at server level.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Mon, 14 Nov 2011 13:26:18 +0000 |
parents | e4b8255e44c3 |
children | 31e6bfca10a5 |
comparison
equal
deleted
inserted
replaced
4277:e4b8255e44c3 | 4278:f57229cba7ad |
---|---|
2363 ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev) | 2363 ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev) |
2364 { | 2364 { |
2365 u_char *p; | 2365 u_char *p; |
2366 size_t size; | 2366 size_t size; |
2367 uintptr_t *code; | 2367 uintptr_t *code; |
2368 ngx_uint_t i; | 2368 ngx_uint_t i, nsrc; |
2369 ngx_array_t headers_names; | 2369 ngx_array_t headers_names; |
2370 #if (NGX_HTTP_CACHE) | |
2371 ngx_array_t params_merged; | |
2372 #endif | |
2370 ngx_keyval_t *src; | 2373 ngx_keyval_t *src; |
2371 ngx_hash_key_t *hk; | 2374 ngx_hash_key_t *hk; |
2372 ngx_hash_init_t hash; | 2375 ngx_hash_init_t hash; |
2373 ngx_http_script_compile_t sc; | 2376 ngx_http_script_compile_t sc; |
2374 ngx_http_script_copy_code_t *copy; | 2377 ngx_http_script_copy_code_t *copy; |
2375 | 2378 |
2376 if (conf->params_source == NULL) { | 2379 if (conf->params_source == NULL) { |
2377 conf->flushes = prev->flushes; | |
2378 conf->params_len = prev->params_len; | |
2379 conf->params = prev->params; | |
2380 conf->params_source = prev->params_source; | 2380 conf->params_source = prev->params_source; |
2381 conf->headers_hash = prev->headers_hash; | 2381 |
2382 | 2382 if (prev->headers_hash.buckets |
2383 #if (NGX_HTTP_CACHE) | 2383 #if (NGX_HTTP_CACHE) |
2384 | 2384 && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL)) |
2385 if (conf->params_source == NULL) { | 2385 #endif |
2386 | 2386 ) |
2387 if ((conf->upstream.cache == NULL) | 2387 { |
2388 == (prev->upstream.cache == NULL)) | 2388 conf->flushes = prev->flushes; |
2389 { | 2389 conf->params_len = prev->params_len; |
2390 return NGX_OK; | 2390 conf->params = prev->params; |
2391 } | 2391 conf->headers_hash = prev->headers_hash; |
2392 | 2392 conf->header_params = prev->header_params; |
2393 /* 6 is a number of ngx_http_fastcgi_cache_headers entries */ | 2393 |
2394 conf->params_source = ngx_array_create(cf->pool, 6, | |
2395 sizeof(ngx_keyval_t)); | |
2396 if (conf->params_source == NULL) { | |
2397 return NGX_ERROR; | |
2398 } | |
2399 } | |
2400 #else | |
2401 | |
2402 if (conf->params_source == NULL) { | |
2403 return NGX_OK; | 2394 return NGX_OK; |
2404 } | 2395 } |
2405 | 2396 } |
2397 | |
2398 if (conf->params_source == NULL | |
2399 #if (NGX_HTTP_CACHE) | |
2400 && (conf->upstream.cache == NULL) | |
2406 #endif | 2401 #endif |
2402 ) | |
2403 { | |
2404 conf->headers_hash.buckets = (void *) 1; | |
2405 return NGX_OK; | |
2407 } | 2406 } |
2408 | 2407 |
2409 conf->params_len = ngx_array_create(cf->pool, 64, 1); | 2408 conf->params_len = ngx_array_create(cf->pool, 64, 1); |
2410 if (conf->params_len == NULL) { | 2409 if (conf->params_len == NULL) { |
2411 return NGX_ERROR; | 2410 return NGX_ERROR; |
2420 != NGX_OK) | 2419 != NGX_OK) |
2421 { | 2420 { |
2422 return NGX_ERROR; | 2421 return NGX_ERROR; |
2423 } | 2422 } |
2424 | 2423 |
2425 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 } | |
2426 | 2432 |
2427 #if (NGX_HTTP_CACHE) | 2433 #if (NGX_HTTP_CACHE) |
2428 | 2434 |
2429 if (conf->upstream.cache) { | 2435 if (conf->upstream.cache) { |
2430 ngx_keyval_t *h, *s; | 2436 ngx_keyval_t *h, *s; |
2431 | 2437 |
2432 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)) |
2433 | 2439 != NGX_OK) |
2434 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++) { | |
2435 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) { | 2462 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) { |
2436 goto next; | 2463 goto next; |
2437 } | 2464 } |
2438 } | 2465 } |
2439 | 2466 |
2440 s = ngx_array_push(conf->params_source); | 2467 s = ngx_array_push(¶ms_merged); |
2441 if (s == NULL) { | 2468 if (s == NULL) { |
2442 return NGX_ERROR; | 2469 return NGX_ERROR; |
2443 } | 2470 } |
2444 | 2471 |
2445 *s = *h; | 2472 *s = *h; |
2446 | 2473 |
2447 src = conf->params_source->elts; | |
2448 | |
2449 next: | 2474 next: |
2450 | 2475 |
2451 h++; | 2476 h++; |
2452 } | 2477 } |
2478 | |
2479 src = params_merged.elts; | |
2480 nsrc = params_merged.nelts; | |
2453 } | 2481 } |
2454 | 2482 |
2455 #endif | 2483 #endif |
2456 | 2484 |
2457 for (i = 0; i < conf->params_source->nelts; i++) { | 2485 for (i = 0; i < nsrc; i++) { |
2458 | 2486 |
2459 if (src[i].key.len > sizeof("HTTP_") - 1 | 2487 if (src[i].key.len > sizeof("HTTP_") - 1 |
2460 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) | 2488 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) |
2461 { | 2489 { |
2462 hk = ngx_array_push(&headers_names); | 2490 hk = ngx_array_push(&headers_names); |