comparison src/http/modules/ngx_http_scgi_module.c @ 642:1b80544421e8 NGINX_1_0_11

nginx 1.0.11 *) Change: now double quotes are encoded in an "echo" SSI-command output. Thanks to Zaur Abasmirzoev. *) Feature: the "image_filter_sharpen" directive. *) Bugfix: a segmentation fault might occur in a worker process if SNI was used; the bug had appeared in 1.0.9. *) Bugfix: SIGWINCH signal did not work after first binary upgrade; the bug had appeared in 1.0.9. *) 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: in the "scgi_param" directive, if complex parameters were used. *) Bugfix: "add_header" and "expires" directives did not work if a request was proxied and response status code was 206. *) Bugfix: in the "expires @time" directive. *) Bugfix: in the ngx_http_flv_module. Thanks to Piotr Sikora. *) Bugfix: in the ngx_http_mp4_module. *) Bugfix: nginx could not be built on FreeBSD 10. *) Bugfix: nginx could not be built on AIX.
author Igor Sysoev <http://sysoev.ru>
date Thu, 15 Dec 2011 00:00:00 +0400
parents 692f4d4d7f10
children ad25218fd14b
comparison
equal deleted inserted replaced
641:e21c9e01ce08 642:1b80544421e8
41 static void ngx_http_scgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc); 41 static void ngx_http_scgi_finalize_request(ngx_http_request_t *r, ngx_int_t rc);
42 42
43 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf); 43 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf);
44 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, 44 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent,
45 void *child); 45 void *child);
46 static ngx_int_t ngx_http_scgi_merge_params(ngx_conf_t *cf,
47 ngx_http_scgi_loc_conf_t *conf, ngx_http_scgi_loc_conf_t *prev);
46 48
47 static char *ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 49 static char *ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
48 static char *ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd, 50 static char *ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd,
49 void *conf); 51 void *conf);
50 52
554 lcode = *(ngx_http_script_len_code_pt *) le.ip; 556 lcode = *(ngx_http_script_len_code_pt *) le.ip;
555 len += lcode(&le); 557 len += lcode(&le);
556 558
557 while (*(uintptr_t *) le.ip) { 559 while (*(uintptr_t *) le.ip) {
558 lcode = *(ngx_http_script_len_code_pt *) le.ip; 560 lcode = *(ngx_http_script_len_code_pt *) le.ip;
559 len += lcode(&le) + 1; 561 len += lcode(&le);
560 } 562 }
563 len++;
564
561 le.ip += sizeof(uintptr_t); 565 le.ip += sizeof(uintptr_t);
562 } 566 }
563 } 567 }
564 568
565 if (scf->upstream.pass_request_headers) { 569 if (scf->upstream.pass_request_headers) {
1057 ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child) 1061 ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
1058 { 1062 {
1059 ngx_http_scgi_loc_conf_t *prev = parent; 1063 ngx_http_scgi_loc_conf_t *prev = parent;
1060 ngx_http_scgi_loc_conf_t *conf = child; 1064 ngx_http_scgi_loc_conf_t *conf = child;
1061 1065
1062 u_char *p;
1063 size_t size; 1066 size_t size;
1064 uintptr_t *code;
1065 ngx_uint_t i;
1066 ngx_array_t headers_names;
1067 ngx_keyval_t *src;
1068 ngx_hash_key_t *hk;
1069 ngx_hash_init_t hash; 1067 ngx_hash_init_t hash;
1070 ngx_http_core_loc_conf_t *clcf; 1068 ngx_http_core_loc_conf_t *clcf;
1071 ngx_http_script_compile_t sc;
1072 ngx_http_script_copy_code_t *copy;
1073 1069
1074 if (conf->upstream.store != 0) { 1070 if (conf->upstream.store != 0) {
1075 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0); 1071 ngx_conf_merge_value(conf->upstream.store, prev->upstream.store, 0);
1076 1072
1077 if (conf->upstream.store_lengths == NULL) { 1073 if (conf->upstream.store_lengths == NULL) {
1305 if (clcf->handler == NULL && clcf->lmt_excpt) { 1301 if (clcf->handler == NULL && clcf->lmt_excpt) {
1306 clcf->handler = ngx_http_scgi_handler; 1302 clcf->handler = ngx_http_scgi_handler;
1307 } 1303 }
1308 } 1304 }
1309 1305
1306 if (ngx_http_scgi_merge_params(cf, conf, prev) != NGX_OK) {
1307 return NGX_CONF_ERROR;
1308 }
1309
1310 return NGX_CONF_OK;
1311 }
1312
1313
1314 static ngx_int_t
1315 ngx_http_scgi_merge_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf,
1316 ngx_http_scgi_loc_conf_t *prev)
1317 {
1318 u_char *p;
1319 size_t size;
1320 uintptr_t *code;
1321 ngx_uint_t i, nsrc;
1322 ngx_array_t headers_names;
1323 #if (NGX_HTTP_CACHE)
1324 ngx_array_t params_merged;
1325 #endif
1326 ngx_keyval_t *src;
1327 ngx_hash_key_t *hk;
1328 ngx_hash_init_t hash;
1329 ngx_http_script_compile_t sc;
1330 ngx_http_script_copy_code_t *copy;
1331
1310 if (conf->params_source == NULL) { 1332 if (conf->params_source == NULL) {
1311 conf->flushes = prev->flushes;
1312 conf->params_len = prev->params_len;
1313 conf->params = prev->params;
1314 conf->params_source = prev->params_source; 1333 conf->params_source = prev->params_source;
1315 conf->headers_hash = prev->headers_hash; 1334
1316 1335 if (prev->headers_hash.buckets
1317 #if (NGX_HTTP_CACHE) 1336 #if (NGX_HTTP_CACHE)
1318 1337 && ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL))
1319 if (conf->params_source == NULL) {
1320
1321 if ((conf->upstream.cache == NULL)
1322 == (prev->upstream.cache == NULL))
1323 {
1324 return NGX_CONF_OK;
1325 }
1326
1327 /* 6 is a number of ngx_http_scgi_cache_headers entries */
1328 conf->params_source = ngx_array_create(cf->pool, 6,
1329 sizeof(ngx_keyval_t));
1330 if (conf->params_source == NULL) {
1331 return NGX_CONF_ERROR;
1332 }
1333 }
1334 #else
1335
1336 if (conf->params_source == NULL) {
1337 return NGX_CONF_OK;
1338 }
1339
1340 #endif 1338 #endif
1339 )
1340 {
1341 conf->flushes = prev->flushes;
1342 conf->params_len = prev->params_len;
1343 conf->params = prev->params;
1344 conf->headers_hash = prev->headers_hash;
1345 conf->header_params = prev->header_params;
1346
1347 return NGX_OK;
1348 }
1349 }
1350
1351 if (conf->params_source == NULL
1352 #if (NGX_HTTP_CACHE)
1353 && (conf->upstream.cache == NULL)
1354 #endif
1355 )
1356 {
1357 conf->headers_hash.buckets = (void *) 1;
1358 return NGX_OK;
1341 } 1359 }
1342 1360
1343 conf->params_len = ngx_array_create(cf->pool, 64, 1); 1361 conf->params_len = ngx_array_create(cf->pool, 64, 1);
1344 if (conf->params_len == NULL) { 1362 if (conf->params_len == NULL) {
1345 return NGX_CONF_ERROR; 1363 return NGX_ERROR;
1346 } 1364 }
1347 1365
1348 conf->params = ngx_array_create(cf->pool, 512, 1); 1366 conf->params = ngx_array_create(cf->pool, 512, 1);
1349 if (conf->params == NULL) { 1367 if (conf->params == NULL) {
1350 return NGX_CONF_ERROR; 1368 return NGX_ERROR;
1351 } 1369 }
1352 1370
1353 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) 1371 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t))
1354 != NGX_OK) 1372 != NGX_OK)
1355 { 1373 {
1356 return NGX_CONF_ERROR; 1374 return NGX_ERROR;
1357 } 1375 }
1358 1376
1359 src = conf->params_source->elts; 1377 if (conf->params_source) {
1378 src = conf->params_source->elts;
1379 nsrc = conf->params_source->nelts;
1380
1381 } else {
1382 src = NULL;
1383 nsrc = 0;
1384 }
1360 1385
1361 #if (NGX_HTTP_CACHE) 1386 #if (NGX_HTTP_CACHE)
1362 1387
1363 if (conf->upstream.cache) { 1388 if (conf->upstream.cache) {
1364 ngx_keyval_t *h, *s; 1389 ngx_keyval_t *h, *s;
1365 1390
1366 for (h = ngx_http_scgi_cache_headers; h->key.len; h++) { 1391 if (ngx_array_init(&params_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t))
1367 1392 != NGX_OK)
1368 for (i = 0; i < conf->params_source->nelts; i++) { 1393 {
1394 return NGX_ERROR;
1395 }
1396
1397 for (i = 0; i < nsrc; i++) {
1398
1399 s = ngx_array_push(&params_merged);
1400 if (s == NULL) {
1401 return NGX_ERROR;
1402 }
1403
1404 *s = src[i];
1405 }
1406
1407 h = ngx_http_scgi_cache_headers;
1408
1409 while (h->key.len) {
1410
1411 src = params_merged.elts;
1412 nsrc = params_merged.nelts;
1413
1414 for (i = 0; i < nsrc; i++) {
1369 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) { 1415 if (ngx_strcasecmp(h->key.data, src[i].key.data) == 0) {
1370 goto next; 1416 goto next;
1371 } 1417 }
1372 } 1418 }
1373 1419
1374 s = ngx_array_push(conf->params_source); 1420 s = ngx_array_push(&params_merged);
1375 if (s == NULL) { 1421 if (s == NULL) {
1376 return NGX_CONF_ERROR; 1422 return NGX_ERROR;
1377 } 1423 }
1378 1424
1379 *s = *h; 1425 *s = *h;
1380 1426
1381 src = conf->params_source->elts;
1382
1383 next: 1427 next:
1384 1428
1385 h++; 1429 h++;
1386 } 1430 }
1431
1432 src = params_merged.elts;
1433 nsrc = params_merged.nelts;
1387 } 1434 }
1388 1435
1389 #endif 1436 #endif
1390 1437
1391 for (i = 0; i < conf->params_source->nelts; i++) { 1438 for (i = 0; i < nsrc; i++) {
1392 1439
1393 if (src[i].key.len > sizeof("HTTP_") - 1 1440 if (src[i].key.len > sizeof("HTTP_") - 1
1394 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0) 1441 && ngx_strncmp(src[i].key.data, "HTTP_", sizeof("HTTP_") - 1) == 0)
1395 { 1442 {
1396 hk = ngx_array_push(&headers_names); 1443 hk = ngx_array_push(&headers_names);
1397 if (hk == NULL) { 1444 if (hk == NULL) {
1398 return NGX_CONF_ERROR; 1445 return NGX_ERROR;
1399 } 1446 }
1400 1447
1401 hk->key.len = src[i].key.len - 5; 1448 hk->key.len = src[i].key.len - 5;
1402 hk->key.data = src[i].key.data + 5; 1449 hk->key.data = src[i].key.data + 5;
1403 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len); 1450 hk->key_hash = ngx_hash_key_lc(hk->key.data, hk->key.len);
1409 } 1456 }
1410 1457
1411 copy = ngx_array_push_n(conf->params_len, 1458 copy = ngx_array_push_n(conf->params_len,
1412 sizeof(ngx_http_script_copy_code_t)); 1459 sizeof(ngx_http_script_copy_code_t));
1413 if (copy == NULL) { 1460 if (copy == NULL) {
1414 return NGX_CONF_ERROR; 1461 return NGX_ERROR;
1415 } 1462 }
1416 1463
1417 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; 1464 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code;
1418 copy->len = src[i].key.len + 1; 1465 copy->len = src[i].key.len + 1;
1419 1466
1422 + src[i].key.len + 1 + sizeof(uintptr_t) - 1) 1469 + src[i].key.len + 1 + sizeof(uintptr_t) - 1)
1423 & ~(sizeof(uintptr_t) - 1); 1470 & ~(sizeof(uintptr_t) - 1);
1424 1471
1425 copy = ngx_array_push_n(conf->params, size); 1472 copy = ngx_array_push_n(conf->params, size);
1426 if (copy == NULL) { 1473 if (copy == NULL) {
1427 return NGX_CONF_ERROR; 1474 return NGX_ERROR;
1428 } 1475 }
1429 1476
1430 copy->code = ngx_http_script_copy_code; 1477 copy->code = ngx_http_script_copy_code;
1431 copy->len = src[i].key.len + 1; 1478 copy->len = src[i].key.len + 1;
1432 1479
1441 sc.flushes = &conf->flushes; 1488 sc.flushes = &conf->flushes;
1442 sc.lengths = &conf->params_len; 1489 sc.lengths = &conf->params_len;
1443 sc.values = &conf->params; 1490 sc.values = &conf->params;
1444 1491
1445 if (ngx_http_script_compile(&sc) != NGX_OK) { 1492 if (ngx_http_script_compile(&sc) != NGX_OK) {
1446 return NGX_CONF_ERROR; 1493 return NGX_ERROR;
1447 } 1494 }
1448 1495
1449 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); 1496 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
1450 if (code == NULL) { 1497 if (code == NULL) {
1451 return NGX_CONF_ERROR; 1498 return NGX_ERROR;
1452 } 1499 }
1453 1500
1454 *code = (uintptr_t) NULL; 1501 *code = (uintptr_t) NULL;
1455 1502
1456 1503
1457 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); 1504 code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
1458 if (code == NULL) { 1505 if (code == NULL) {
1459 return NGX_CONF_ERROR; 1506 return NGX_ERROR;
1460 } 1507 }
1461 1508
1462 *code = (uintptr_t) NULL; 1509 *code = (uintptr_t) NULL;
1463 } 1510 }
1464 1511
1465 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); 1512 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t));
1466 if (code == NULL) { 1513 if (code == NULL) {
1467 return NGX_CONF_ERROR; 1514 return NGX_ERROR;
1468 } 1515 }
1469 1516
1470 *code = (uintptr_t) NULL; 1517 *code = (uintptr_t) NULL;
1471 1518
1472 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); 1519 code = ngx_array_push_n(conf->params, sizeof(uintptr_t));
1473 if (code == NULL) { 1520 if (code == NULL) {
1474 return NGX_CONF_ERROR; 1521 return NGX_ERROR;
1475 } 1522 }
1476 1523
1477 *code = (uintptr_t) NULL; 1524 *code = (uintptr_t) NULL;
1478 1525
1479 conf->header_params = headers_names.nelts; 1526 conf->header_params = headers_names.nelts;
1484 hash.bucket_size = 64; 1531 hash.bucket_size = 64;
1485 hash.name = "scgi_params_hash"; 1532 hash.name = "scgi_params_hash";
1486 hash.pool = cf->pool; 1533 hash.pool = cf->pool;
1487 hash.temp_pool = NULL; 1534 hash.temp_pool = NULL;
1488 1535
1489 if (ngx_hash_init(&hash, headers_names.elts, headers_names.nelts) != NGX_OK) 1536 return ngx_hash_init(&hash, headers_names.elts, headers_names.nelts);
1490 {
1491 return NGX_CONF_ERROR;
1492 }
1493
1494 return NGX_CONF_OK;
1495 } 1537 }
1496 1538
1497 1539
1498 static char * 1540 static char *
1499 ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 1541 ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)