Mercurial > hg > nginx-quic
comparison src/http/modules/ngx_http_scgi_module.c @ 5908:f8e80f8c7fc7
Upstream: moved header lists to separate structures.
No functional changes.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Wed, 19 Nov 2014 17:33:22 +0300 |
parents | 195561ef367f |
children | 8d0cf26ce071 |
comparison
equal
deleted
inserted
replaced
5907:195561ef367f | 5908:f8e80f8c7fc7 |
---|---|
10 #include <ngx_core.h> | 10 #include <ngx_core.h> |
11 #include <ngx_http.h> | 11 #include <ngx_http.h> |
12 | 12 |
13 | 13 |
14 typedef struct { | 14 typedef struct { |
15 ngx_array_t *flushes; | |
16 ngx_array_t *lengths; | |
17 ngx_array_t *values; | |
18 ngx_uint_t number; | |
19 ngx_hash_t hash; | |
20 } ngx_http_scgi_params_t; | |
21 | |
22 | |
23 typedef struct { | |
15 ngx_http_upstream_conf_t upstream; | 24 ngx_http_upstream_conf_t upstream; |
16 | 25 |
17 ngx_array_t *flushes; | 26 ngx_http_scgi_params_t params; |
18 ngx_array_t *params_len; | |
19 ngx_array_t *params; | |
20 ngx_array_t *params_source; | 27 ngx_array_t *params_source; |
21 | |
22 ngx_hash_t headers_hash; | |
23 ngx_uint_t header_params; | |
24 | 28 |
25 ngx_array_t *scgi_lengths; | 29 ngx_array_t *scgi_lengths; |
26 ngx_array_t *scgi_values; | 30 ngx_array_t *scgi_values; |
27 | 31 |
28 #if (NGX_HTTP_CACHE) | 32 #if (NGX_HTTP_CACHE) |
42 | 46 |
43 static void *ngx_http_scgi_create_loc_conf(ngx_conf_t *cf); | 47 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, | 48 static char *ngx_http_scgi_merge_loc_conf(ngx_conf_t *cf, void *parent, |
45 void *child); | 49 void *child); |
46 static ngx_int_t ngx_http_scgi_init_params(ngx_conf_t *cf, | 50 static ngx_int_t ngx_http_scgi_init_params(ngx_conf_t *cf, |
47 ngx_http_scgi_loc_conf_t *conf); | 51 ngx_http_scgi_loc_conf_t *conf, ngx_http_scgi_params_t *params); |
48 | 52 |
49 static char *ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); | 53 static char *ngx_http_scgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, void *conf); |
50 static char *ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd, | 54 static char *ngx_http_scgi_store(ngx_conf_t *cf, ngx_command_t *cmd, |
51 void *conf); | 55 void *conf); |
52 | 56 |
577 ngx_str_t content_length; | 581 ngx_str_t content_length; |
578 ngx_uint_t i, n, hash, skip_empty, header_params; | 582 ngx_uint_t i, n, hash, skip_empty, header_params; |
579 ngx_chain_t *cl, *body; | 583 ngx_chain_t *cl, *body; |
580 ngx_list_part_t *part; | 584 ngx_list_part_t *part; |
581 ngx_table_elt_t *header, **ignored; | 585 ngx_table_elt_t *header, **ignored; |
586 ngx_http_scgi_params_t *params; | |
582 ngx_http_script_code_pt code; | 587 ngx_http_script_code_pt code; |
583 ngx_http_script_engine_t e, le; | 588 ngx_http_script_engine_t e, le; |
584 ngx_http_scgi_loc_conf_t *scf; | 589 ngx_http_scgi_loc_conf_t *scf; |
585 ngx_http_script_len_code_pt lcode; | 590 ngx_http_script_len_code_pt lcode; |
586 u_char buffer[NGX_OFF_T_LEN]; | 591 u_char buffer[NGX_OFF_T_LEN]; |
601 header_params = 0; | 606 header_params = 0; |
602 ignored = NULL; | 607 ignored = NULL; |
603 | 608 |
604 scf = ngx_http_get_module_loc_conf(r, ngx_http_scgi_module); | 609 scf = ngx_http_get_module_loc_conf(r, ngx_http_scgi_module); |
605 | 610 |
606 if (scf->params_len) { | 611 params = &scf->params; |
612 | |
613 if (params->lengths) { | |
607 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | 614 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); |
608 | 615 |
609 ngx_http_script_flush_no_cacheable_variables(r, scf->flushes); | 616 ngx_http_script_flush_no_cacheable_variables(r, params->flushes); |
610 le.flushed = 1; | 617 le.flushed = 1; |
611 | 618 |
612 le.ip = scf->params_len->elts; | 619 le.ip = params->lengths->elts; |
613 le.request = r; | 620 le.request = r; |
614 | 621 |
615 while (*(uintptr_t *) le.ip) { | 622 while (*(uintptr_t *) le.ip) { |
616 | 623 |
617 lcode = *(ngx_http_script_len_code_pt *) le.ip; | 624 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
636 if (scf->upstream.pass_request_headers) { | 643 if (scf->upstream.pass_request_headers) { |
637 | 644 |
638 allocated = 0; | 645 allocated = 0; |
639 lowcase_key = NULL; | 646 lowcase_key = NULL; |
640 | 647 |
641 if (scf->header_params) { | 648 if (params->number) { |
642 n = 0; | 649 n = 0; |
643 part = &r->headers_in.headers.part; | 650 part = &r->headers_in.headers.part; |
644 | 651 |
645 while (part) { | 652 while (part) { |
646 n += part->nelts; | 653 n += part->nelts; |
666 part = part->next; | 673 part = part->next; |
667 header = part->elts; | 674 header = part->elts; |
668 i = 0; | 675 i = 0; |
669 } | 676 } |
670 | 677 |
671 if (scf->header_params) { | 678 if (params->number) { |
672 if (allocated < header[i].key.len) { | 679 if (allocated < header[i].key.len) { |
673 allocated = header[i].key.len + 16; | 680 allocated = header[i].key.len + 16; |
674 lowcase_key = ngx_pnalloc(r->pool, allocated); | 681 lowcase_key = ngx_pnalloc(r->pool, allocated); |
675 if (lowcase_key == NULL) { | 682 if (lowcase_key == NULL) { |
676 return NGX_ERROR; | 683 return NGX_ERROR; |
691 | 698 |
692 hash = ngx_hash(hash, ch); | 699 hash = ngx_hash(hash, ch); |
693 lowcase_key[n] = ch; | 700 lowcase_key[n] = ch; |
694 } | 701 } |
695 | 702 |
696 if (ngx_hash_find(&scf->headers_hash, hash, lowcase_key, n)) { | 703 if (ngx_hash_find(¶ms->hash, hash, lowcase_key, n)) { |
697 ignored[header_params++] = &header[i]; | 704 ignored[header_params++] = &header[i]; |
698 continue; | 705 continue; |
699 } | 706 } |
700 } | 707 } |
701 | 708 |
719 cl->buf = b; | 726 cl->buf = b; |
720 | 727 |
721 b->last = ngx_sprintf(b->last, "%ui:CONTENT_LENGTH%Z%V%Z", | 728 b->last = ngx_sprintf(b->last, "%ui:CONTENT_LENGTH%Z%V%Z", |
722 len, &content_length); | 729 len, &content_length); |
723 | 730 |
724 if (scf->params_len) { | 731 if (params->lengths) { |
725 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | 732 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); |
726 | 733 |
727 e.ip = scf->params->elts; | 734 e.ip = params->values->elts; |
728 e.pos = b->last; | 735 e.pos = b->last; |
729 e.request = r; | 736 e.request = r; |
730 e.flushed = 1; | 737 e.flushed = 1; |
731 | 738 |
732 le.ip = scf->params_len->elts; | 739 le.ip = params->lengths->elts; |
733 | 740 |
734 while (*(uintptr_t *) le.ip) { | 741 while (*(uintptr_t *) le.ip) { |
735 | 742 |
736 lcode = *(ngx_http_script_len_code_pt *) le.ip; | 743 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
737 lcode(&le); /* key length */ | 744 lcode(&le); /* key length */ |
1448 | 1455 |
1449 #if (NGX_HTTP_CACHE) | 1456 #if (NGX_HTTP_CACHE) |
1450 if ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL)) | 1457 if ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL)) |
1451 #endif | 1458 #endif |
1452 { | 1459 { |
1453 conf->flushes = prev->flushes; | |
1454 conf->params_len = prev->params_len; | |
1455 conf->params = prev->params; | 1460 conf->params = prev->params; |
1456 conf->headers_hash = prev->headers_hash; | 1461 } |
1457 conf->header_params = prev->header_params; | 1462 } |
1458 } | 1463 |
1459 } | 1464 if (ngx_http_scgi_init_params(cf, conf, &conf->params) != NGX_OK) { |
1460 | |
1461 if (ngx_http_scgi_init_params(cf, conf) != NGX_OK) { | |
1462 return NGX_CONF_ERROR; | 1465 return NGX_CONF_ERROR; |
1463 } | 1466 } |
1464 | 1467 |
1465 return NGX_CONF_OK; | 1468 return NGX_CONF_OK; |
1466 } | 1469 } |
1467 | 1470 |
1468 | 1471 |
1469 static ngx_int_t | 1472 static ngx_int_t |
1470 ngx_http_scgi_init_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf) | 1473 ngx_http_scgi_init_params(ngx_conf_t *cf, ngx_http_scgi_loc_conf_t *conf, |
1474 ngx_http_scgi_params_t *params) | |
1471 { | 1475 { |
1472 u_char *p; | 1476 u_char *p; |
1473 size_t size; | 1477 size_t size; |
1474 uintptr_t *code; | 1478 uintptr_t *code; |
1475 ngx_uint_t i, nsrc; | 1479 ngx_uint_t i, nsrc; |
1481 ngx_hash_init_t hash; | 1485 ngx_hash_init_t hash; |
1482 ngx_http_upstream_param_t *src; | 1486 ngx_http_upstream_param_t *src; |
1483 ngx_http_script_compile_t sc; | 1487 ngx_http_script_compile_t sc; |
1484 ngx_http_script_copy_code_t *copy; | 1488 ngx_http_script_copy_code_t *copy; |
1485 | 1489 |
1486 if (conf->headers_hash.buckets) { | 1490 if (params->hash.buckets) { |
1487 return NGX_OK; | 1491 return NGX_OK; |
1488 } | 1492 } |
1489 | 1493 |
1490 if (conf->params_source == NULL | 1494 if (conf->params_source == NULL |
1491 #if (NGX_HTTP_CACHE) | 1495 #if (NGX_HTTP_CACHE) |
1492 && (conf->upstream.cache == NULL) | 1496 && (conf->upstream.cache == NULL) |
1493 #endif | 1497 #endif |
1494 ) | 1498 ) |
1495 { | 1499 { |
1496 conf->headers_hash.buckets = (void *) 1; | 1500 params->hash.buckets = (void *) 1; |
1497 return NGX_OK; | 1501 return NGX_OK; |
1498 } | 1502 } |
1499 | 1503 |
1500 conf->params_len = ngx_array_create(cf->pool, 64, 1); | 1504 params->lengths = ngx_array_create(cf->pool, 64, 1); |
1501 if (conf->params_len == NULL) { | 1505 if (params->lengths == NULL) { |
1502 return NGX_ERROR; | 1506 return NGX_ERROR; |
1503 } | 1507 } |
1504 | 1508 |
1505 conf->params = ngx_array_create(cf->pool, 512, 1); | 1509 params->values = ngx_array_create(cf->pool, 512, 1); |
1506 if (conf->params == NULL) { | 1510 if (params->values == NULL) { |
1507 return NGX_ERROR; | 1511 return NGX_ERROR; |
1508 } | 1512 } |
1509 | 1513 |
1510 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) | 1514 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) |
1511 != NGX_OK) | 1515 != NGX_OK) |
1596 if (src[i].value.len == 0) { | 1600 if (src[i].value.len == 0) { |
1597 continue; | 1601 continue; |
1598 } | 1602 } |
1599 } | 1603 } |
1600 | 1604 |
1601 copy = ngx_array_push_n(conf->params_len, | 1605 copy = ngx_array_push_n(params->lengths, |
1602 sizeof(ngx_http_script_copy_code_t)); | 1606 sizeof(ngx_http_script_copy_code_t)); |
1603 if (copy == NULL) { | 1607 if (copy == NULL) { |
1604 return NGX_ERROR; | 1608 return NGX_ERROR; |
1605 } | 1609 } |
1606 | 1610 |
1607 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; | 1611 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; |
1608 copy->len = src[i].key.len + 1; | 1612 copy->len = src[i].key.len + 1; |
1609 | 1613 |
1610 copy = ngx_array_push_n(conf->params_len, | 1614 copy = ngx_array_push_n(params->lengths, |
1611 sizeof(ngx_http_script_copy_code_t)); | 1615 sizeof(ngx_http_script_copy_code_t)); |
1612 if (copy == NULL) { | 1616 if (copy == NULL) { |
1613 return NGX_ERROR; | 1617 return NGX_ERROR; |
1614 } | 1618 } |
1615 | 1619 |
1619 | 1623 |
1620 size = (sizeof(ngx_http_script_copy_code_t) | 1624 size = (sizeof(ngx_http_script_copy_code_t) |
1621 + src[i].key.len + 1 + sizeof(uintptr_t) - 1) | 1625 + src[i].key.len + 1 + sizeof(uintptr_t) - 1) |
1622 & ~(sizeof(uintptr_t) - 1); | 1626 & ~(sizeof(uintptr_t) - 1); |
1623 | 1627 |
1624 copy = ngx_array_push_n(conf->params, size); | 1628 copy = ngx_array_push_n(params->values, size); |
1625 if (copy == NULL) { | 1629 if (copy == NULL) { |
1626 return NGX_ERROR; | 1630 return NGX_ERROR; |
1627 } | 1631 } |
1628 | 1632 |
1629 copy->code = ngx_http_script_copy_code; | 1633 copy->code = ngx_http_script_copy_code; |
1635 | 1639 |
1636 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | 1640 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); |
1637 | 1641 |
1638 sc.cf = cf; | 1642 sc.cf = cf; |
1639 sc.source = &src[i].value; | 1643 sc.source = &src[i].value; |
1640 sc.flushes = &conf->flushes; | 1644 sc.flushes = ¶ms->flushes; |
1641 sc.lengths = &conf->params_len; | 1645 sc.lengths = ¶ms->lengths; |
1642 sc.values = &conf->params; | 1646 sc.values = ¶ms->values; |
1643 | 1647 |
1644 if (ngx_http_script_compile(&sc) != NGX_OK) { | 1648 if (ngx_http_script_compile(&sc) != NGX_OK) { |
1645 return NGX_ERROR; | 1649 return NGX_ERROR; |
1646 } | 1650 } |
1647 | 1651 |
1648 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | 1652 code = ngx_array_push_n(params->lengths, sizeof(uintptr_t)); |
1649 if (code == NULL) { | 1653 if (code == NULL) { |
1650 return NGX_ERROR; | 1654 return NGX_ERROR; |
1651 } | 1655 } |
1652 | 1656 |
1653 *code = (uintptr_t) NULL; | 1657 *code = (uintptr_t) NULL; |
1654 | 1658 |
1655 | 1659 |
1656 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); | 1660 code = ngx_array_push_n(params->values, sizeof(uintptr_t)); |
1657 if (code == NULL) { | 1661 if (code == NULL) { |
1658 return NGX_ERROR; | 1662 return NGX_ERROR; |
1659 } | 1663 } |
1660 | 1664 |
1661 *code = (uintptr_t) NULL; | 1665 *code = (uintptr_t) NULL; |
1662 } | 1666 } |
1663 | 1667 |
1664 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | 1668 code = ngx_array_push_n(params->lengths, sizeof(uintptr_t)); |
1665 if (code == NULL) { | 1669 if (code == NULL) { |
1666 return NGX_ERROR; | 1670 return NGX_ERROR; |
1667 } | 1671 } |
1668 | 1672 |
1669 *code = (uintptr_t) NULL; | 1673 *code = (uintptr_t) NULL; |
1670 | 1674 |
1671 conf->header_params = headers_names.nelts; | 1675 params->number = headers_names.nelts; |
1672 | 1676 |
1673 hash.hash = &conf->headers_hash; | 1677 hash.hash = ¶ms->hash; |
1674 hash.key = ngx_hash_key_lc; | 1678 hash.key = ngx_hash_key_lc; |
1675 hash.max_size = 512; | 1679 hash.max_size = 512; |
1676 hash.bucket_size = 64; | 1680 hash.bucket_size = 64; |
1677 hash.name = "scgi_params_hash"; | 1681 hash.name = "scgi_params_hash"; |
1678 hash.pool = cf->pool; | 1682 hash.pool = cf->pool; |