Mercurial > hg > nginx
comparison src/http/modules/ngx_http_scgi_module.c @ 4331:059260de158d
SCGI: added "if_not_empty" flag support to the "scgi_param" directive.
author | Valentin Bartenev <vbart@nginx.com> |
---|---|
date | Fri, 09 Dec 2011 14:03:06 +0000 |
parents | 56cb2255735a |
children | 16ebad9447ee |
comparison
equal
deleted
inserted
replaced
4330:5ee5ddec17b1 | 4331:059260de158d |
---|---|
276 NGX_HTTP_LOC_CONF_OFFSET, | 276 NGX_HTTP_LOC_CONF_OFFSET, |
277 offsetof(ngx_http_scgi_loc_conf_t, upstream.next_upstream), | 277 offsetof(ngx_http_scgi_loc_conf_t, upstream.next_upstream), |
278 &ngx_http_scgi_next_upstream_masks }, | 278 &ngx_http_scgi_next_upstream_masks }, |
279 | 279 |
280 { ngx_string("scgi_param"), | 280 { ngx_string("scgi_param"), |
281 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE2, | 281 NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE23, |
282 ngx_conf_set_keyval_slot, | 282 ngx_http_upstream_param_set_slot, |
283 NGX_HTTP_LOC_CONF_OFFSET, | 283 NGX_HTTP_LOC_CONF_OFFSET, |
284 offsetof(ngx_http_scgi_loc_conf_t, params_source), | 284 offsetof(ngx_http_scgi_loc_conf_t, params_source), |
285 NULL }, | 285 NULL }, |
286 | 286 |
287 { ngx_string("scgi_pass_header"), | 287 { ngx_string("scgi_pass_header"), |
517 | 517 |
518 static ngx_int_t | 518 static ngx_int_t |
519 ngx_http_scgi_create_request(ngx_http_request_t *r) | 519 ngx_http_scgi_create_request(ngx_http_request_t *r) |
520 { | 520 { |
521 u_char ch, *key, *val, *lowcase_key; | 521 u_char ch, *key, *val, *lowcase_key; |
522 size_t len, allocated; | 522 size_t len, key_len, val_len, allocated; |
523 ngx_buf_t *b; | 523 ngx_buf_t *b; |
524 ngx_str_t *content_length; | 524 ngx_str_t *content_length; |
525 ngx_uint_t i, n, hash, header_params; | 525 ngx_uint_t i, n, hash, skip_empty, header_params; |
526 ngx_chain_t *cl, *body; | 526 ngx_chain_t *cl, *body; |
527 ngx_list_part_t *part; | 527 ngx_list_part_t *part; |
528 ngx_table_elt_t *header, **ignored; | 528 ngx_table_elt_t *header, **ignored; |
529 ngx_http_script_code_pt code; | 529 ngx_http_script_code_pt code; |
530 ngx_http_script_engine_t e, le; | 530 ngx_http_script_engine_t e, le; |
552 le.request = r; | 552 le.request = r; |
553 | 553 |
554 while (*(uintptr_t *) le.ip) { | 554 while (*(uintptr_t *) le.ip) { |
555 | 555 |
556 lcode = *(ngx_http_script_len_code_pt *) le.ip; | 556 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
557 len += lcode(&le); | 557 key_len = lcode(&le); |
558 | 558 |
559 while (*(uintptr_t *) le.ip) { | 559 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
560 skip_empty = lcode(&le); | |
561 | |
562 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) { | |
560 lcode = *(ngx_http_script_len_code_pt *) le.ip; | 563 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
561 len += lcode(&le); | 564 } |
562 } | |
563 len++; | |
564 | |
565 le.ip += sizeof(uintptr_t); | 565 le.ip += sizeof(uintptr_t); |
566 | |
567 if (skip_empty && val_len == 0) { | |
568 continue; | |
569 } | |
570 | |
571 len += key_len + val_len + 1; | |
566 } | 572 } |
567 } | 573 } |
568 | 574 |
569 if (scf->upstream.pass_request_headers) { | 575 if (scf->upstream.pass_request_headers) { |
570 | 576 |
663 e.ip = scf->params->elts; | 669 e.ip = scf->params->elts; |
664 e.pos = b->last; | 670 e.pos = b->last; |
665 e.request = r; | 671 e.request = r; |
666 e.flushed = 1; | 672 e.flushed = 1; |
667 | 673 |
668 while (*(uintptr_t *) e.ip) { | 674 le.ip = scf->params_len->elts; |
675 | |
676 while (*(uintptr_t *) le.ip) { | |
677 | |
678 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
679 lcode(&le); /* key length */ | |
680 | |
681 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
682 skip_empty = lcode(&le); | |
683 | |
684 for (val_len = 0; *(uintptr_t *) le.ip; val_len += lcode(&le)) { | |
685 lcode = *(ngx_http_script_len_code_pt *) le.ip; | |
686 } | |
687 le.ip += sizeof(uintptr_t); | |
688 | |
689 if (skip_empty && val_len == 0) { | |
690 e.skip = 1; | |
691 | |
692 while (*(uintptr_t *) e.ip) { | |
693 code = *(ngx_http_script_code_pt *) e.ip; | |
694 code((ngx_http_script_engine_t *) &e); | |
695 } | |
696 e.ip += sizeof(uintptr_t); | |
697 | |
698 e.skip = 0; | |
699 | |
700 continue; | |
701 } | |
669 | 702 |
670 #if (NGX_DEBUG) | 703 #if (NGX_DEBUG) |
671 key = e.pos; | 704 key = e.pos; |
672 #endif | 705 #endif |
673 code = *(ngx_http_script_code_pt *) e.ip; | 706 code = *(ngx_http_script_code_pt *) e.ip; |
1321 ngx_uint_t i, nsrc; | 1354 ngx_uint_t i, nsrc; |
1322 ngx_array_t headers_names; | 1355 ngx_array_t headers_names; |
1323 #if (NGX_HTTP_CACHE) | 1356 #if (NGX_HTTP_CACHE) |
1324 ngx_array_t params_merged; | 1357 ngx_array_t params_merged; |
1325 #endif | 1358 #endif |
1326 ngx_keyval_t *src; | |
1327 ngx_hash_key_t *hk; | 1359 ngx_hash_key_t *hk; |
1328 ngx_hash_init_t hash; | 1360 ngx_hash_init_t hash; |
1361 ngx_http_upstream_param_t *src; | |
1329 ngx_http_script_compile_t sc; | 1362 ngx_http_script_compile_t sc; |
1330 ngx_http_script_copy_code_t *copy; | 1363 ngx_http_script_copy_code_t *copy; |
1331 | 1364 |
1332 if (conf->params_source == NULL) { | 1365 if (conf->params_source == NULL) { |
1333 conf->params_source = prev->params_source; | 1366 conf->params_source = prev->params_source; |
1384 } | 1417 } |
1385 | 1418 |
1386 #if (NGX_HTTP_CACHE) | 1419 #if (NGX_HTTP_CACHE) |
1387 | 1420 |
1388 if (conf->upstream.cache) { | 1421 if (conf->upstream.cache) { |
1389 ngx_keyval_t *h, *s; | 1422 ngx_keyval_t *h; |
1390 | 1423 ngx_http_upstream_param_t *s; |
1391 if (ngx_array_init(¶ms_merged, cf->temp_pool, 4, sizeof(ngx_keyval_t)) | 1424 |
1425 if (ngx_array_init(¶ms_merged, cf->temp_pool, 4, | |
1426 sizeof(ngx_http_upstream_param_t)) | |
1392 != NGX_OK) | 1427 != NGX_OK) |
1393 { | 1428 { |
1394 return NGX_ERROR; | 1429 return NGX_ERROR; |
1395 } | 1430 } |
1396 | 1431 |
1420 s = ngx_array_push(¶ms_merged); | 1455 s = ngx_array_push(¶ms_merged); |
1421 if (s == NULL) { | 1456 if (s == NULL) { |
1422 return NGX_ERROR; | 1457 return NGX_ERROR; |
1423 } | 1458 } |
1424 | 1459 |
1425 *s = *h; | 1460 s->key = h->key; |
1461 s->value = h->value; | |
1462 s->skip_empty = 0; | |
1426 | 1463 |
1427 next: | 1464 next: |
1428 | 1465 |
1429 h++; | 1466 h++; |
1430 } | 1467 } |
1461 return NGX_ERROR; | 1498 return NGX_ERROR; |
1462 } | 1499 } |
1463 | 1500 |
1464 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; | 1501 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; |
1465 copy->len = src[i].key.len + 1; | 1502 copy->len = src[i].key.len + 1; |
1503 | |
1504 copy = ngx_array_push_n(conf->params_len, | |
1505 sizeof(ngx_http_script_copy_code_t)); | |
1506 if (copy == NULL) { | |
1507 return NGX_ERROR; | |
1508 } | |
1509 | |
1510 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; | |
1511 copy->len = src[i].skip_empty; | |
1466 | 1512 |
1467 | 1513 |
1468 size = (sizeof(ngx_http_script_copy_code_t) | 1514 size = (sizeof(ngx_http_script_copy_code_t) |
1469 + src[i].key.len + 1 + sizeof(uintptr_t) - 1) | 1515 + src[i].key.len + 1 + sizeof(uintptr_t) - 1) |
1470 & ~(sizeof(uintptr_t) - 1); | 1516 & ~(sizeof(uintptr_t) - 1); |