Klaus Demo nginx / 7377d07
Merge of r4275, r4276, r4278, r4279: Fixes for proxy_set_header, fastcgi/scgi/uwsgi_param inheritance: *) Fixed proxy_set_header inheritance with proxy_cache (ticket #45). Headers cleared with cache enabled (If-Modified-Since etc.) might be cleared in unrelated servers/locations without proxy_cache enabled if proxy_cache was used in some server/location. Example config which triggered the problem: proxy_set_header X-Test "test"; server { location /1 { proxy_cache name; proxy_pass ... } } server { location /2 { proxy_pass ... } } Another one: server { proxy_cache name; location /1 { proxy_pass ... } location /2 { proxy_cache off; proxy_pass ... } } In both cases If-Modified-Since header wasn't sent to backend in location /2. Fix is to not modify conf->headers_source, but instead merge user-supplied headers from conf->headers_source and default headers (either cache or not) into separate headers_merged array. *) Fixed proxy_set_header inheritance with proxy_set_body. *) Separate functions to merge fastcgi/scgi/uwsgi params. No functional changes. *) 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. Maxim Dounin 10 years ago
4 changed file(s) with 345 addition(s) and 216 deletion(s). Raw diff Collapse all Expand all
141141 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf);
142142 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf,
143143 void *parent, void *child);
144 static ngx_int_t ngx_http_fastcgi_merge_params(ngx_conf_t *cf,
145 ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev);
146
144147 static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r,
145148 ngx_http_variable_value_t *v, uintptr_t data);
146149 static ngx_int_t ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r,
20242027 ngx_http_fastcgi_loc_conf_t *prev = parent;
20252028 ngx_http_fastcgi_loc_conf_t *conf = child;
20262029
2027 u_char *p;
20282030 size_t size;
2029 uintptr_t *code;
2030 ngx_uint_t i;
2031 ngx_array_t headers_names;
2032 ngx_keyval_t *src;
2033 ngx_hash_key_t *hk;
20342031 ngx_hash_init_t hash;
20352032 ngx_http_core_loc_conf_t *clcf;
2036 ngx_http_script_compile_t sc;
2037 ngx_http_script_copy_code_t *copy;
20382033
20392034 if (conf->upstream.store != 0) {
20402035 ngx_conf_merge_value(conf->upstream.store,
22922287 }
22932288 #endif
22942289
2290 if (ngx_http_fastcgi_merge_params(cf, conf, prev) != NGX_OK) {
2291 return NGX_CONF_ERROR;
2292 }
2293
2294 return NGX_CONF_OK;
2295 }
2296
2297
2298 static ngx_int_t
2299 ngx_http_fastcgi_merge_params(ngx_conf_t *cf,
2300 ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_loc_conf_t *prev)
2301 {
2302 u_char *p;
2303 size_t size;
2304 uintptr_t *code;
2305 ngx_uint_t i, nsrc;
2306 ngx_array_t headers_names;
2307 #if (NGX_HTTP_CACHE)
2308 ngx_array_t params_merged;
2309 #endif
2310 ngx_keyval_t *src;
2311 ngx_hash_key_t *hk;
2312 ngx_hash_init_t hash;
2313 ngx_http_script_compile_t sc;
2314 ngx_http_script_copy_code_t *copy;
2315
22952316 if (conf->params_source == NULL) {
2296 conf->flushes = prev->flushes;
2297 conf->params_len = prev->params_len;
2298 conf->params = prev->params;
22992317 conf->params_source = prev->params_source;
2300 conf->headers_hash = prev->headers_hash;
2301
2318
2319 if (prev->headers_hash.buckets
23022320 #if (NGX_HTTP_CACHE)
2303
2304 if (conf->params_source == NULL) {
2305
2306 if ((conf->upstream.cache == NULL)
2307 == (prev->upstream.cache == NULL))
2308 {
2309 return NGX_CONF_OK;
2310 }
2311
2312 /* 6 is a number of ngx_http_fastcgi_cache_headers entries */
2313 conf->params_source = ngx_array_create(cf->pool, 6,
2314 sizeof(ngx_keyval_t));
2315 if (conf->params_source == NULL) {
2316 return NGX_CONF_ERROR;
2317 }
2318 }
2319 #else
2320
2321 if (conf->params_source == NULL) {
2322 return NGX_CONF_OK;
2323 }
2324
2321 && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
23252322 #endif
2323 )
2324 {
2325 conf->flushes = prev->flushes;
2326 conf->params_len = prev->params_len;
2327 conf->params = prev->params;
2328 conf->headers_hash = prev->headers_hash;
2329 conf->header_params = prev->header_params;
2330
2331 return NGX_OK;
2332 }
2333 }
2334
2335 if (conf->params_source == NULL
2336 #if (NGX_HTTP_CACHE)
2337 && (conf->upstream.cache == NULL)
2338 #endif
2339 )
2340 {
2341 conf->headers_hash.buckets = (void *) 1;
2342 return NGX_OK;
23262343 }
23272344
23282345 conf->params_len = ngx_array_create(cf->pool, 64, 1);
23292346 if (conf->params_len == NULL) {
2330 return NGX_CONF_ERROR;
2347 return NGX_ERROR;
23312348 }
23322349
23332350 conf->params = ngx_array_create(cf->pool, 512, 1);
23342351 if (conf->params == NULL) {
2335 return NGX_CONF_ERROR;
2352 return NGX_ERROR;
23362353 }
23372354
23382355 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t))
23392356 != NGX_OK)
23402357 {
2341 return NGX_CONF_ERROR;
2342 }
2343
2344 src = conf->params_source->elts;
2358 return NGX_ERROR;
2359 }
2360
2361 if (conf->params_source) {
2362 src = conf->params_source->elts;
2363 nsrc = conf->params_source->nelts;
2364
2365 } else {
2366 src = NULL;
2367 nsrc = 0;
2368 }
23452369
23462370 #if (NGX_HTTP_CACHE)
23472371
23482372 if (conf->upstream.cache) {
23492373 ngx_keyval_t *h, *s;
23502374
2351 for (h = ngx_http_fastcgi_cache_headers; h->key.len; h++) {
2352
2353 for (i = 0; i < conf->params_source->nelts; i++) {
2375 if (ngx_array_init(&params_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
2376 != NGX_OK)
2377 {
2378 return NGX_ERROR;
2379 }
2380
2381 for (i = 0; i < nsrc; i++) {
2382
2383 s = ngx_array_push(&params_merged);
2384 if (s == NULL) {
2385 return NGX_ERROR;
2386 }
2387
2388 *s = src[i];
2389 }
2390
2391 h = ngx_http_fastcgi_cache_headers;
2392
2393 while (h->key.len) {
2394
2395 src = params_merged.elts;
2396 nsrc = params_merged.nelts;
2397
2398 for (i = 0; i < nsrc; i++) {
23542399 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
23552400 goto next;
23562401 }
23572402 }
23582403
2359 s = ngx_array_push(conf->params_source);
2404 s = ngx_array_push(&params_merged);
23602405 if (s == NULL) {
2361 return NGX_CONF_ERROR;
2406 return NGX_ERROR;
23622407 }
23632408
23642409 *s = *h;
23652410
2366 src = conf->params_source->elts;
2367
23682411 next:
23692412
23702413 h++;
23712414 }
2415
2416 src = params_merged.elts;
2417 nsrc = params_merged.nelts;
23722418 }
23732419
23742420 #endif
23752421
2376 for (i = 0; i < conf->params_source->nelts; i++) {
2422 for (i = 0; i < nsrc; i++) {
23772423
23782424 if (src[i].key.len > sizeof("HTTP_") - 1
23792425 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0)
23802426 {
23812427 hk = ngx_array_push(&headers_names);
23822428 if (hk == NULL) {
2383 return NGX_CONF_ERROR;
2429 return NGX_ERROR;
23842430 }
23852431
23862432 hk->key.len = src[i].key.len - 5;
23962442 copy = ngx_array_push_n(conf->params_len,
23972443 sizeof(ngx_http_script_copy_code_t));
23982444 if (copy == NULL) {
2399 return NGX_CONF_ERROR;
2445 return NGX_ERROR;
24002446 }
24012447
24022448 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
24052451
24062452 size = (sizeof(ngx_http_script_copy_code_t)
24072453 + src[i].key.len + sizeof(uintptr_t) - 1)
2408 & ~(sizeof(uintptr_t) - 1);
2454 & ~(sizeof(uintptr_t) - 1);
24092455
24102456 copy = ngx_array_push_n(conf->params, size);
24112457 if (copy == NULL) {
2412 return NGX_CONF_ERROR;
2458 return NGX_ERROR;
24132459 }
24142460
24152461 copy->code = ngx_http_script_copy_code;
24282474 sc.values = &conf->params;
24292475
24302476 if (ngx_http_script_compile(&sc) != NGX_OK) {
2431 return NGX_CONF_ERROR;
2477 return NGX_ERROR;
24322478 }
24332479
24342480 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
24352481 if (code == NULL) {
2436 return NGX_CONF_ERROR;
2482 return NGX_ERROR;
24372483 }
24382484
24392485 *code = (uintptr_t) NULL;
24412487
24422488 code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
24432489 if (code == NULL) {
2444 return NGX_CONF_ERROR;
2490 return NGX_ERROR;
24452491 }
24462492
24472493 *code = (uintptr_t) NULL;
24492495
24502496 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
24512497 if (code == NULL) {
2452 return NGX_CONF_ERROR;
2498 return NGX_ERROR;
24532499 }
24542500
24552501 *code = (uintptr_t) NULL;
2456
24572502
24582503 conf->header_params = headers_names.nelts;
24592504
24652510 hash.pool = cf->pool;
24662511 hash.temp_pool = NULL;
24672512
2468 if (ngx_hash_init(&hash, headers_names.elts, headers_names.nelts) != NGX_OK)
2469 {
2470 return NGX_CONF_ERROR;
2471 }
2472
2473 return NGX_CONF_OK;
2513 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts);
24742514 }
24752515
24762516
17211721
17221722 u_char *p;
17231723 size_t size;
1724 ngx_keyval_t *s;
17251724 ngx_hash_init_t hash;
17261725 ngx_http_core_loc_conf_t *clcf;
17271726 ngx_http_proxy_redirect_t *pr;
20662065 if (ngx_http_script_compile(&sc) != NGX_OK) {
20672066 return NGX_CONF_ERROR;
20682067 }
2069
2070 if (conf->headers_source == NULL) {
2071 conf->headers_source = ngx_array_create(cf->pool, 4,
2072 sizeof(ngx_keyval_t));
2073 if (conf->headers_source == NULL) {
2074 return NGX_CONF_ERROR;
2075 }
2076 }
2077
2078 s = ngx_array_push(conf->headers_source);
2079 if (s == NULL) {
2080 return NGX_CONF_ERROR;
2081 }
2082
2083 ngx_str_set(&s->key, "Content-Length");
2084 ngx_str_set(&s->value, "$proxy_internal_body_length");
20852068 }
20862069
20872070 if (ngx_http_proxy_merge_headers(cf, conf, prev) != NGX_OK) {
21002083 size_t size;
21012084 uintptr_t *code;
21022085 ngx_uint_t i;
2103 ngx_array_t headers_names;
2086 ngx_array_t headers_names, headers_merged;
21042087 ngx_keyval_t *src, *s, *h;
21052088 ngx_hash_key_t *hk;
21062089 ngx_hash_init_t hash;
21162099 }
21172100
21182101 if (conf->headers_set_hash.buckets
2102 && ((conf->body_source.data == NULL)
2103 == (prev->body_source.data == NULL))
21192104 #if (NGX_HTTP_CACHE)
21202105 && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
21212106 #endif
21312116 return NGX_ERROR;
21322117 }
21332118
2119 if (ngx_array_init(&headers_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
2120 != NGX_OK)
2121 {
2122 return NGX_ERROR;
2123 }
2124
21342125 if (conf->headers_source == NULL) {
21352126 conf->headers_source = ngx_array_create(cf->pool, 4,
21362127 sizeof(ngx_keyval_t));
21502141 }
21512142
21522143
2153 src = conf->headers_source->elts;
2154
21552144 #if (NGX_HTTP_CACHE)
21562145
21572146 h = conf->upstream.cache ? ngx_http_proxy_cache_headers:
21622151
21632152 #endif
21642153
2154 src = conf->headers_source->elts;
2155 for (i = 0; i < conf->headers_source->nelts; i++) {
2156
2157 s = ngx_array_push(&headers_merged);
2158 if (s == NULL) {
2159 return NGX_ERROR;
2160 }
2161
2162 *s = src[i];
2163 }
2164
21652165 while (h->key.len) {
21662166
2167 for (i = 0; i < conf->headers_source->nelts; i++) {
2167 src = headers_merged.elts;
2168 for (i = 0; i < headers_merged.nelts; i++) {
21682169 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
21692170 goto next;
21702171 }
21712172 }
21722173
2173 s = ngx_array_push(conf->headers_source);
2174 s = ngx_array_push(&headers_merged);
21742175 if (s == NULL) {
21752176 return NGX_ERROR;
21762177 }
21772178
21782179 *s = *h;
21792180
2180 src = conf->headers_source->elts;
2181
21822181 next:
21832182
21842183 h++;
21852184 }
21862185
2187
2188 src = conf->headers_source->elts;
2189 for (i = 0; i < conf->headers_source->nelts; i++) {
2186 if (conf->body_source.data) {
2187 s = ngx_array_push(&headers_merged);
2188 if (s == NULL) {
2189 return NGX_ERROR;
2190 }
2191
2192 ngx_str_set(&s->key, "Content-Length");
2193 ngx_str_set(&s->value, "$proxy_internal_body_length");
2194 }
2195
2196
2197 src = headers_merged.elts;
2198 for (i = 0; i < headers_merged.nelts; i++) {
21902199
21912200 hk = ngx_array_push(&headers_names);
21922201 if (hk == NULL) {
4242 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf);
4343 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent,
4444 void *child);
45 static ngx_int_t ngx_http_scgi_merge_params(ngx_conf_t *cf,
46 ngx_http_scgi_loc_conf_t *conf, ngx_http_scgi_loc_conf_t *prev);
4547
4648 static char *ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
4749 static char *ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd,
10581060 ngx_http_scgi_loc_conf_t *prev = parent;
10591061 ngx_http_scgi_loc_conf_t *conf = child;
10601062
1061 u_char *p;
10621063 size_t size;
1063 uintptr_t *code;
1064 ngx_uint_t i;
1065 ngx_array_t headers_names;
1066 ngx_keyval_t *src;
1067 ngx_hash_key_t *hk;
10681064 ngx_hash_init_t hash;
10691065 ngx_http_core_loc_conf_t *clcf;
1070 ngx_http_script_compile_t sc;
1071 ngx_http_script_copy_code_t *copy;
10721066
10731067 if (conf->upstream.store != 0) {
10741068 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0);
13061300 }
13071301 }
13081302
1303 if (ngx_http_scgi_merge_params(cf, conf, prev) != NGX_OK) {
1304 return NGX_CONF_ERROR;
1305 }
1306
1307 return NGX_CONF_OK;
1308 }
1309
1310
1311 static ngx_int_t
1312 ngx_http_scgi_merge_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
1313 ngx_http_scgi_loc_conf_t *prev)
1314 {
1315 u_char *p;
1316 size_t size;
1317 uintptr_t *code;
1318 ngx_uint_t i, nsrc;
1319 ngx_array_t headers_names;
1320 #if (NGX_HTTP_CACHE)
1321 ngx_array_t params_merged;
1322 #endif
1323 ngx_keyval_t *src;
1324 ngx_hash_key_t *hk;
1325 ngx_hash_init_t hash;
1326 ngx_http_script_compile_t sc;
1327 ngx_http_script_copy_code_t *copy;
1328
13091329 if (conf->params_source == NULL) {
1310 conf->flushes = prev->flushes;
1311 conf->params_len = prev->params_len;
1312 conf->params = prev->params;
13131330 conf->params_source = prev->params_source;
1314 conf->headers_hash = prev->headers_hash;
1315
1331
1332 if (prev->headers_hash.buckets
13161333 #if (NGX_HTTP_CACHE)
1317
1318 if (conf->params_source == NULL) {
1319
1320 if ((conf->upstream.cache == NULL)
1321 == (prev->upstream.cache == NULL))
1322 {
1323 return NGX_CONF_OK;
1324 }
1325
1326 /* 6 is a number of ngx_http_scgi_cache_headers entries */
1327 conf->params_source = ngx_array_create(cf->pool, 6,
1328 sizeof(ngx_keyval_t));
1329 if (conf->params_source == NULL) {
1330 return NGX_CONF_ERROR;
1331 }
1332 }
1333 #else
1334
1335 if (conf->params_source == NULL) {
1336 return NGX_CONF_OK;
1337 }
1338
1334 && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
13391335 #endif
1336 )
1337 {
1338 conf->flushes = prev->flushes;
1339 conf->params_len = prev->params_len;
1340 conf->params = prev->params;
1341 conf->headers_hash = prev->headers_hash;
1342 conf->header_params = prev->header_params;
1343
1344 return NGX_OK;
1345 }
1346 }
1347
1348 if (conf->params_source == NULL
1349 #if (NGX_HTTP_CACHE)
1350 && (conf->upstream.cache == NULL)
1351 #endif
1352 )
1353 {
1354 conf->headers_hash.buckets = (void *) 1;
1355 return NGX_OK;
13401356 }
13411357
13421358 conf->params_len = ngx_array_create(cf->pool, 64, 1);
13431359 if (conf->params_len == NULL) {
1344 return NGX_CONF_ERROR;
1360 return NGX_ERROR;
13451361 }
13461362
13471363 conf->params = ngx_array_create(cf->pool, 512, 1);
13481364 if (conf->params == NULL) {
1349 return NGX_CONF_ERROR;
1365 return NGX_ERROR;
13501366 }
13511367
13521368 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t))
13531369 != NGX_OK)
13541370 {
1355 return NGX_CONF_ERROR;
1356 }
1357
1358 src = conf->params_source->elts;
1371 return NGX_ERROR;
1372 }
1373
1374 if (conf->params_source) {
1375 src = conf->params_source->elts;
1376 nsrc = conf->params_source->nelts;
1377
1378 } else {
1379 src = NULL;
1380 nsrc = 0;
1381 }
13591382
13601383 #if (NGX_HTTP_CACHE)
13611384
13621385 if (conf->upstream.cache) {
13631386 ngx_keyval_t *h, *s;
13641387
1365 for (h = ngx_http_scgi_cache_headers; h->key.len; h++) {
1366
1367 for (i = 0; i < conf->params_source->nelts; i++) {
1388 if (ngx_array_init(&params_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
1389 != NGX_OK)
1390 {
1391 return NGX_ERROR;
1392 }
1393
1394 for (i = 0; i < nsrc; i++) {
1395
1396 s = ngx_array_push(&params_merged);
1397 if (s == NULL) {
1398 return NGX_ERROR;
1399 }
1400
1401 *s = src[i];
1402 }
1403
1404 h = ngx_http_scgi_cache_headers;
1405
1406 while (h->key.len) {
1407
1408 src = params_merged.elts;
1409 nsrc = params_merged.nelts;
1410
1411 for (i = 0; i < nsrc; i++) {
13681412 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
13691413 goto next;
13701414 }
13711415 }
13721416
1373 s = ngx_array_push(conf->params_source);
1417 s = ngx_array_push(&params_merged);
13741418 if (s == NULL) {
1375 return NGX_CONF_ERROR;
1419 return NGX_ERROR;
13761420 }
13771421
13781422 *s = *h;
13791423
1380 src = conf->params_source->elts;
1381
13821424 next:
13831425
13841426 h++;
13851427 }
1428
1429 src = params_merged.elts;
1430 nsrc = params_merged.nelts;
13861431 }
13871432
13881433 #endif
13891434
1390 for (i = 0; i < conf->params_source->nelts; i++) {
1435 for (i = 0; i < nsrc; i++) {
13911436
13921437 if (src[i].key.len > sizeof("HTTP_") - 1
13931438 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0)
13941439 {
13951440 hk = ngx_array_push(&headers_names);
13961441 if (hk == NULL) {
1397 return NGX_CONF_ERROR;
1442 return NGX_ERROR;
13981443 }
13991444
14001445 hk->key.len = src[i].key.len - 5;
14101455 copy = ngx_array_push_n(conf->params_len,
14111456 sizeof(ngx_http_script_copy_code_t));
14121457 if (copy == NULL) {
1413 return NGX_CONF_ERROR;
1458 return NGX_ERROR;
14141459 }
14151460
14161461 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
14231468
14241469 copy = ngx_array_push_n(conf->params, size);
14251470 if (copy == NULL) {
1426 return NGX_CONF_ERROR;
1471 return NGX_ERROR;
14271472 }
14281473
14291474 copy->code = ngx_http_script_copy_code;
14421487 sc.values = &conf->params;
14431488
14441489 if (ngx_http_script_compile(&sc) != NGX_OK) {
1445 return NGX_CONF_ERROR;
1490 return NGX_ERROR;
14461491 }
14471492
14481493 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
14491494 if (code == NULL) {
1450 return NGX_CONF_ERROR;
1495 return NGX_ERROR;
14511496 }
14521497
14531498 *code = (uintptr_t) NULL;
14551500
14561501 code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
14571502 if (code == NULL) {
1458 return NGX_CONF_ERROR;
1503 return NGX_ERROR;
14591504 }
14601505
14611506 *code = (uintptr_t) NULL;
14631508
14641509 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
14651510 if (code == NULL) {
1466 return NGX_CONF_ERROR;
1511 return NGX_ERROR;
14671512 }
14681513
14691514 *code = (uintptr_t) NULL;
14701515
14711516 code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
14721517 if (code == NULL) {
1473 return NGX_CONF_ERROR;
1518 return NGX_ERROR;
14741519 }
14751520
14761521 *code = (uintptr_t) NULL;
14851530 hash.pool = cf->pool;
14861531 hash.temp_pool = NULL;
14871532
1488 if (ngx_hash_init(&hash, headers_names.elts, headers_names.nelts) != NGX_OK)
1489 {
1490 return NGX_CONF_ERROR;
1491 }
1492
1493 return NGX_CONF_OK;
1533 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts);
14941534 }
14951535
14961536
4949 static void *ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf);
5050 static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent,
5151 void *child);
52 static ngx_int_t ngx_http_uwsgi_merge_params(ngx_conf_t *cf,
53 ngx_http_uwsgi_loc_conf_t *conf, ngx_http_uwsgi_loc_conf_t *prev);
5254
5355 static char *ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd,
5456 void *conf);
11111113 ngx_http_uwsgi_loc_conf_t *prev = parent;
11121114 ngx_http_uwsgi_loc_conf_t *conf = child;
11131115
1114 u_char *p;
11151116 size_t size;
1116 uintptr_t *code;
1117 ngx_uint_t i;
1118 ngx_array_t headers_names;
1119 ngx_keyval_t *src;
1120 ngx_hash_key_t *hk;
11211117 ngx_hash_init_t hash;
11221118 ngx_http_core_loc_conf_t *clcf;
1123 ngx_http_script_compile_t sc;
1124 ngx_http_script_copy_code_t *copy;
11251119
11261120 if (conf->upstream.store != 0) {
11271121 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0);
13641358 ngx_conf_merge_uint_value(conf->modifier1, prev->modifier1, 0);
13651359 ngx_conf_merge_uint_value(conf->modifier2, prev->modifier2, 0);
13661360
1361 if (ngx_http_uwsgi_merge_params(cf, conf, prev) != NGX_OK) {
1362 return NGX_CONF_ERROR;
1363 }
1364
1365 return NGX_CONF_OK;
1366 }
1367
1368
1369 static ngx_int_t
1370 ngx_http_uwsgi_merge_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf,
1371 ngx_http_uwsgi_loc_conf_t *prev)
1372 {
1373 u_char *p;
1374 size_t size;
1375 uintptr_t *code;
1376 ngx_uint_t i, nsrc;
1377 ngx_array_t headers_names;
1378 #if (NGX_HTTP_CACHE)
1379 ngx_array_t params_merged;
1380 #endif
1381 ngx_keyval_t *src;
1382 ngx_hash_key_t *hk;
1383 ngx_hash_init_t hash;
1384 ngx_http_script_compile_t sc;
1385 ngx_http_script_copy_code_t *copy;
1386
13671387 if (conf->params_source == NULL) {
1368 conf->flushes = prev->flushes;
1369 conf->params_len = prev->params_len;
1370 conf->params = prev->params;
13711388 conf->params_source = prev->params_source;
1372 conf->headers_hash = prev->headers_hash;
1373
1389
1390 if (prev->headers_hash.buckets
13741391 #if (NGX_HTTP_CACHE)
1375
1376 if (conf->params_source == NULL) {
1377
1378 if ((conf->upstream.cache == NULL)
1379 == (prev->upstream.cache == NULL))
1380 {
1381 return NGX_CONF_OK;
1382 }
1383
1384 /* 6 is a number of ngx_http_uwsgi_cache_headers entries */
1385 conf->params_source = ngx_array_create(cf->pool, 6,
1386 sizeof(ngx_keyval_t));
1387 if (conf->params_source == NULL) {
1388 return NGX_CONF_ERROR;
1389 }
1390 }
1391 #else
1392
1393 if (conf->params_source == NULL) {
1394 return NGX_CONF_OK;
1395 }
1396
1392 && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
13971393 #endif
1394 )
1395 {
1396 conf->flushes = prev->flushes;
1397 conf->params_len = prev->params_len;
1398 conf->params = prev->params;
1399 conf->headers_hash = prev->headers_hash;
1400 conf->header_params = prev->header_params;
1401
1402 return NGX_OK;
1403 }
1404 }
1405
1406 if (conf->params_source == NULL
1407 #if (NGX_HTTP_CACHE)
1408 && (conf->upstream.cache == NULL)
1409 #endif
1410 )
1411 {
1412 conf->headers_hash.buckets = (void *) 1;
1413 return NGX_OK;
13981414 }
13991415
14001416 conf->params_len = ngx_array_create(cf->pool, 64, 1);
14011417 if (conf->params_len == NULL) {
1402 return NGX_CONF_ERROR;
1418 return NGX_ERROR;
14031419 }
14041420
14051421 conf->params = ngx_array_create(cf->pool, 512, 1);
14061422 if (conf->params == NULL) {
1407 return NGX_CONF_ERROR;
1423 return NGX_ERROR;
14081424 }
14091425
14101426 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t))
14111427 != NGX_OK)
14121428 {
1413 return NGX_CONF_ERROR;
1414 }
1415
1416 src = conf->params_source->elts;
1429 return NGX_ERROR;
1430 }
1431
1432 if (conf->params_source) {
1433 src = conf->params_source->elts;
1434 nsrc = conf->params_source->nelts;
1435
1436 } else {
1437 src = NULL;
1438 nsrc = 0;
1439 }
14171440
14181441 #if (NGX_HTTP_CACHE)
14191442
14201443 if (conf->upstream.cache) {
14211444 ngx_keyval_t *h, *s;
14221445
1423 for (h = ngx_http_uwsgi_cache_headers; h->key.len; h++) {
1424
1425 for (i = 0; i < conf->params_source->nelts; i++) {
1446 if (ngx_array_init(&params_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
1447 != NGX_OK)
1448 {
1449 return NGX_ERROR;
1450 }
1451
1452 for (i = 0; i < nsrc; i++) {
1453
1454 s = ngx_array_push(&params_merged);
1455 if (s == NULL) {
1456 return NGX_ERROR;
1457 }
1458
1459 *s = src[i];
1460 }
1461
1462 h = ngx_http_uwsgi_cache_headers;
1463
1464 while (h->key.len) {
1465
1466 src = params_merged.elts;
1467 nsrc = params_merged.nelts;
1468
1469 for (i = 0; i < nsrc; i++) {
14261470 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
14271471 goto next;
14281472 }
14291473 }
14301474
1431 s = ngx_array_push(conf->params_source);
1475 s = ngx_array_push(&params_merged);
14321476 if (s == NULL) {
1433 return NGX_CONF_ERROR;
1477 return NGX_ERROR;
14341478 }
14351479
14361480 *s = *h;
14371481
1438 src = conf->params_source->elts;
1439
14401482 next:
14411483
14421484 h++;
14431485 }
1486
1487 src = params_merged.elts;
1488 nsrc = params_merged.nelts;
14441489 }
14451490
14461491 #endif
14471492
1448 for (i = 0; i < conf->params_source->nelts; i++) {
1493 for (i = 0; i < nsrc; i++) {
14491494
14501495 if (src[i].key.len > sizeof("HTTP_") - 1
14511496 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0)
14521497 {
14531498 hk = ngx_array_push(&headers_names);
14541499 if (hk == NULL) {
1455 return NGX_CONF_ERROR;
1500 return NGX_ERROR;
14561501 }
14571502
14581503 hk->key.len = src[i].key.len - 5;
14681513 copy = ngx_array_push_n(conf->params_len,
14691514 sizeof(ngx_http_script_copy_code_t));
14701515 if (copy == NULL) {
1471 return NGX_CONF_ERROR;
1516 return NGX_ERROR;
14721517 }
14731518
14741519 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
14811526
14821527 copy = ngx_array_push_n(conf->params, size);
14831528 if (copy == NULL) {
1484 return NGX_CONF_ERROR;
1529 return NGX_ERROR;
14851530 }
14861531
14871532 copy->code = ngx_http_script_copy_code;
15001545 sc.values = &conf->params;
15011546
15021547 if (ngx_http_script_compile(&sc) != NGX_OK) {
1503 return NGX_CONF_ERROR;
1548 return NGX_ERROR;
15041549 }
15051550
15061551 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
15071552 if (code == NULL) {
1508 return NGX_CONF_ERROR;
1553 return NGX_ERROR;
15091554 }
15101555
15111556 *code = (uintptr_t) NULL;
15131558
15141559 code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
15151560 if (code == NULL) {
1516 return NGX_CONF_ERROR;
1561 return NGX_ERROR;
15171562 }
15181563
15191564 *code = (uintptr_t) NULL;
15211566
15221567 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
15231568 if (code == NULL) {
1524 return NGX_CONF_ERROR;
1569 return NGX_ERROR;
15251570 }
15261571
15271572 *code = (uintptr_t) NULL;
15361581 hash.pool = cf->pool;
15371582 hash.temp_pool = NULL;
15381583
1539 if (ngx_hash_init(&hash, headers_names.elts, headers_names.nelts) != NGX_OK)
1540 {
1541 return NGX_CONF_ERROR;
1542 }
1543
1544 return NGX_CONF_OK;
1584 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts);
15451585 }
15461586
15471587