Mercurial > hg > nginx
comparison src/http/modules/ngx_http_uwsgi_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 |
---|---|
11 #include <ngx_core.h> | 11 #include <ngx_core.h> |
12 #include <ngx_http.h> | 12 #include <ngx_http.h> |
13 | 13 |
14 | 14 |
15 typedef struct { | 15 typedef struct { |
16 ngx_array_t *flushes; | |
17 ngx_array_t *lengths; | |
18 ngx_array_t *values; | |
19 ngx_uint_t number; | |
20 ngx_hash_t hash; | |
21 } ngx_http_uwsgi_params_t; | |
22 | |
23 | |
24 typedef struct { | |
16 ngx_http_upstream_conf_t upstream; | 25 ngx_http_upstream_conf_t upstream; |
17 | 26 |
18 ngx_array_t *flushes; | 27 ngx_http_uwsgi_params_t params; |
19 ngx_array_t *params_len; | |
20 ngx_array_t *params; | |
21 ngx_array_t *params_source; | 28 ngx_array_t *params_source; |
22 | |
23 ngx_hash_t headers_hash; | |
24 ngx_uint_t header_params; | |
25 | 29 |
26 ngx_array_t *uwsgi_lengths; | 30 ngx_array_t *uwsgi_lengths; |
27 ngx_array_t *uwsgi_values; | 31 ngx_array_t *uwsgi_values; |
28 | 32 |
29 #if (NGX_HTTP_CACHE) | 33 #if (NGX_HTTP_CACHE) |
61 | 65 |
62 static void *ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf); | 66 static void *ngx_http_uwsgi_create_loc_conf(ngx_conf_t *cf); |
63 static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent, | 67 static char *ngx_http_uwsgi_merge_loc_conf(ngx_conf_t *cf, void *parent, |
64 void *child); | 68 void *child); |
65 static ngx_int_t ngx_http_uwsgi_init_params(ngx_conf_t *cf, | 69 static ngx_int_t ngx_http_uwsgi_init_params(ngx_conf_t *cf, |
66 ngx_http_uwsgi_loc_conf_t *conf); | 70 ngx_http_uwsgi_loc_conf_t *conf, ngx_http_uwsgi_params_t *params); |
67 | 71 |
68 static char *ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, | 72 static char *ngx_http_uwsgi_pass(ngx_conf_t *cf, ngx_command_t *cmd, |
69 void *conf); | 73 void *conf); |
70 static char *ngx_http_uwsgi_store(ngx_conf_t *cf, ngx_command_t *cmd, | 74 static char *ngx_http_uwsgi_store(ngx_conf_t *cf, ngx_command_t *cmd, |
71 void *conf); | 75 void *conf); |
777 ngx_uint_t i, n, hash, skip_empty, header_params; | 781 ngx_uint_t i, n, hash, skip_empty, header_params; |
778 ngx_buf_t *b; | 782 ngx_buf_t *b; |
779 ngx_chain_t *cl, *body; | 783 ngx_chain_t *cl, *body; |
780 ngx_list_part_t *part; | 784 ngx_list_part_t *part; |
781 ngx_table_elt_t *header, **ignored; | 785 ngx_table_elt_t *header, **ignored; |
786 ngx_http_uwsgi_params_t *params; | |
782 ngx_http_script_code_pt code; | 787 ngx_http_script_code_pt code; |
783 ngx_http_script_engine_t e, le; | 788 ngx_http_script_engine_t e, le; |
784 ngx_http_uwsgi_loc_conf_t *uwcf; | 789 ngx_http_uwsgi_loc_conf_t *uwcf; |
785 ngx_http_script_len_code_pt lcode; | 790 ngx_http_script_len_code_pt lcode; |
786 | 791 |
788 header_params = 0; | 793 header_params = 0; |
789 ignored = NULL; | 794 ignored = NULL; |
790 | 795 |
791 uwcf = ngx_http_get_module_loc_conf(r, ngx_http_uwsgi_module); | 796 uwcf = ngx_http_get_module_loc_conf(r, ngx_http_uwsgi_module); |
792 | 797 |
793 if (uwcf->params_len) { | 798 params = &uwcf->params; |
799 | |
800 if (params->lengths) { | |
794 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | 801 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); |
795 | 802 |
796 ngx_http_script_flush_no_cacheable_variables(r, uwcf->flushes); | 803 ngx_http_script_flush_no_cacheable_variables(r, params->flushes); |
797 le.flushed = 1; | 804 le.flushed = 1; |
798 | 805 |
799 le.ip = uwcf->params_len->elts; | 806 le.ip = params->lengths->elts; |
800 le.request = r; | 807 le.request = r; |
801 | 808 |
802 while (*(uintptr_t *) le.ip) { | 809 while (*(uintptr_t *) le.ip) { |
803 | 810 |
804 lcode = *(ngx_http_script_len_code_pt *) le.ip; | 811 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
823 if (uwcf->upstream.pass_request_headers) { | 830 if (uwcf->upstream.pass_request_headers) { |
824 | 831 |
825 allocated = 0; | 832 allocated = 0; |
826 lowcase_key = NULL; | 833 lowcase_key = NULL; |
827 | 834 |
828 if (uwcf->header_params) { | 835 if (params->number) { |
829 n = 0; | 836 n = 0; |
830 part = &r->headers_in.headers.part; | 837 part = &r->headers_in.headers.part; |
831 | 838 |
832 while (part) { | 839 while (part) { |
833 n += part->nelts; | 840 n += part->nelts; |
853 part = part->next; | 860 part = part->next; |
854 header = part->elts; | 861 header = part->elts; |
855 i = 0; | 862 i = 0; |
856 } | 863 } |
857 | 864 |
858 if (uwcf->header_params) { | 865 if (params->number) { |
859 if (allocated < header[i].key.len) { | 866 if (allocated < header[i].key.len) { |
860 allocated = header[i].key.len + 16; | 867 allocated = header[i].key.len + 16; |
861 lowcase_key = ngx_pnalloc(r->pool, allocated); | 868 lowcase_key = ngx_pnalloc(r->pool, allocated); |
862 if (lowcase_key == NULL) { | 869 if (lowcase_key == NULL) { |
863 return NGX_ERROR; | 870 return NGX_ERROR; |
878 | 885 |
879 hash = ngx_hash(hash, ch); | 886 hash = ngx_hash(hash, ch); |
880 lowcase_key[n] = ch; | 887 lowcase_key[n] = ch; |
881 } | 888 } |
882 | 889 |
883 if (ngx_hash_find(&uwcf->headers_hash, hash, lowcase_key, n)) { | 890 if (ngx_hash_find(¶ms->hash, hash, lowcase_key, n)) { |
884 ignored[header_params++] = &header[i]; | 891 ignored[header_params++] = &header[i]; |
885 continue; | 892 continue; |
886 } | 893 } |
887 } | 894 } |
888 | 895 |
917 *b->last++ = (u_char) uwcf->modifier1; | 924 *b->last++ = (u_char) uwcf->modifier1; |
918 *b->last++ = (u_char) (len & 0xff); | 925 *b->last++ = (u_char) (len & 0xff); |
919 *b->last++ = (u_char) ((len >> 8) & 0xff); | 926 *b->last++ = (u_char) ((len >> 8) & 0xff); |
920 *b->last++ = (u_char) uwcf->modifier2; | 927 *b->last++ = (u_char) uwcf->modifier2; |
921 | 928 |
922 if (uwcf->params_len) { | 929 if (params->lengths) { |
923 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | 930 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); |
924 | 931 |
925 e.ip = uwcf->params->elts; | 932 e.ip = params->values->elts; |
926 e.pos = b->last; | 933 e.pos = b->last; |
927 e.request = r; | 934 e.request = r; |
928 e.flushed = 1; | 935 e.flushed = 1; |
929 | 936 |
930 le.ip = uwcf->params_len->elts; | 937 le.ip = params->lengths->elts; |
931 | 938 |
932 while (*(uintptr_t *) le.ip) { | 939 while (*(uintptr_t *) le.ip) { |
933 | 940 |
934 lcode = *(ngx_http_script_len_code_pt *) le.ip; | 941 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
935 key_len = (u_char) lcode (&le); | 942 key_len = (u_char) lcode (&le); |
1710 | 1717 |
1711 #if (NGX_HTTP_CACHE) | 1718 #if (NGX_HTTP_CACHE) |
1712 if ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL)) | 1719 if ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL)) |
1713 #endif | 1720 #endif |
1714 { | 1721 { |
1715 conf->flushes = prev->flushes; | |
1716 conf->params_len = prev->params_len; | |
1717 conf->params = prev->params; | 1722 conf->params = prev->params; |
1718 conf->headers_hash = prev->headers_hash; | 1723 } |
1719 conf->header_params = prev->header_params; | 1724 } |
1720 } | 1725 |
1721 } | 1726 if (ngx_http_uwsgi_init_params(cf, conf, &conf->params) != NGX_OK) { |
1722 | |
1723 if (ngx_http_uwsgi_init_params(cf, conf) != NGX_OK) { | |
1724 return NGX_CONF_ERROR; | 1727 return NGX_CONF_ERROR; |
1725 } | 1728 } |
1726 | 1729 |
1727 return NGX_CONF_OK; | 1730 return NGX_CONF_OK; |
1728 } | 1731 } |
1729 | 1732 |
1730 | 1733 |
1731 static ngx_int_t | 1734 static ngx_int_t |
1732 ngx_http_uwsgi_init_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf) | 1735 ngx_http_uwsgi_init_params(ngx_conf_t *cf, ngx_http_uwsgi_loc_conf_t *conf, |
1736 ngx_http_uwsgi_params_t *params) | |
1733 { | 1737 { |
1734 u_char *p; | 1738 u_char *p; |
1735 size_t size; | 1739 size_t size; |
1736 uintptr_t *code; | 1740 uintptr_t *code; |
1737 ngx_uint_t i, nsrc; | 1741 ngx_uint_t i, nsrc; |
1743 ngx_hash_init_t hash; | 1747 ngx_hash_init_t hash; |
1744 ngx_http_upstream_param_t *src; | 1748 ngx_http_upstream_param_t *src; |
1745 ngx_http_script_compile_t sc; | 1749 ngx_http_script_compile_t sc; |
1746 ngx_http_script_copy_code_t *copy; | 1750 ngx_http_script_copy_code_t *copy; |
1747 | 1751 |
1748 if (conf->headers_hash.buckets) { | 1752 if (params->hash.buckets) { |
1749 return NGX_OK; | 1753 return NGX_OK; |
1750 } | 1754 } |
1751 | 1755 |
1752 if (conf->params_source == NULL | 1756 if (conf->params_source == NULL |
1753 #if (NGX_HTTP_CACHE) | 1757 #if (NGX_HTTP_CACHE) |
1754 && (conf->upstream.cache == NULL) | 1758 && (conf->upstream.cache == NULL) |
1755 #endif | 1759 #endif |
1756 ) | 1760 ) |
1757 { | 1761 { |
1758 conf->headers_hash.buckets = (void *) 1; | 1762 params->hash.buckets = (void *) 1; |
1759 return NGX_OK; | 1763 return NGX_OK; |
1760 } | 1764 } |
1761 | 1765 |
1762 conf->params_len = ngx_array_create(cf->pool, 64, 1); | 1766 params->lengths = ngx_array_create(cf->pool, 64, 1); |
1763 if (conf->params_len == NULL) { | 1767 if (params->lengths == NULL) { |
1764 return NGX_ERROR; | 1768 return NGX_ERROR; |
1765 } | 1769 } |
1766 | 1770 |
1767 conf->params = ngx_array_create(cf->pool, 512, 1); | 1771 params->values = ngx_array_create(cf->pool, 512, 1); |
1768 if (conf->params == NULL) { | 1772 if (params->values == NULL) { |
1769 return NGX_ERROR; | 1773 return NGX_ERROR; |
1770 } | 1774 } |
1771 | 1775 |
1772 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) | 1776 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) |
1773 != NGX_OK) | 1777 != NGX_OK) |
1858 if (src[i].value.len == 0) { | 1862 if (src[i].value.len == 0) { |
1859 continue; | 1863 continue; |
1860 } | 1864 } |
1861 } | 1865 } |
1862 | 1866 |
1863 copy = ngx_array_push_n(conf->params_len, | 1867 copy = ngx_array_push_n(params->lengths, |
1864 sizeof(ngx_http_script_copy_code_t)); | 1868 sizeof(ngx_http_script_copy_code_t)); |
1865 if (copy == NULL) { | 1869 if (copy == NULL) { |
1866 return NGX_ERROR; | 1870 return NGX_ERROR; |
1867 } | 1871 } |
1868 | 1872 |
1869 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; | 1873 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; |
1870 copy->len = src[i].key.len; | 1874 copy->len = src[i].key.len; |
1871 | 1875 |
1872 copy = ngx_array_push_n(conf->params_len, | 1876 copy = ngx_array_push_n(params->lengths, |
1873 sizeof(ngx_http_script_copy_code_t)); | 1877 sizeof(ngx_http_script_copy_code_t)); |
1874 if (copy == NULL) { | 1878 if (copy == NULL) { |
1875 return NGX_ERROR; | 1879 return NGX_ERROR; |
1876 } | 1880 } |
1877 | 1881 |
1881 | 1885 |
1882 size = (sizeof(ngx_http_script_copy_code_t) | 1886 size = (sizeof(ngx_http_script_copy_code_t) |
1883 + src[i].key.len + sizeof(uintptr_t) - 1) | 1887 + src[i].key.len + sizeof(uintptr_t) - 1) |
1884 & ~(sizeof(uintptr_t) - 1); | 1888 & ~(sizeof(uintptr_t) - 1); |
1885 | 1889 |
1886 copy = ngx_array_push_n(conf->params, size); | 1890 copy = ngx_array_push_n(params->values, size); |
1887 if (copy == NULL) { | 1891 if (copy == NULL) { |
1888 return NGX_ERROR; | 1892 return NGX_ERROR; |
1889 } | 1893 } |
1890 | 1894 |
1891 copy->code = ngx_http_script_copy_code; | 1895 copy->code = ngx_http_script_copy_code; |
1897 | 1901 |
1898 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | 1902 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); |
1899 | 1903 |
1900 sc.cf = cf; | 1904 sc.cf = cf; |
1901 sc.source = &src[i].value; | 1905 sc.source = &src[i].value; |
1902 sc.flushes = &conf->flushes; | 1906 sc.flushes = ¶ms->flushes; |
1903 sc.lengths = &conf->params_len; | 1907 sc.lengths = ¶ms->lengths; |
1904 sc.values = &conf->params; | 1908 sc.values = ¶ms->values; |
1905 | 1909 |
1906 if (ngx_http_script_compile(&sc) != NGX_OK) { | 1910 if (ngx_http_script_compile(&sc) != NGX_OK) { |
1907 return NGX_ERROR; | 1911 return NGX_ERROR; |
1908 } | 1912 } |
1909 | 1913 |
1910 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | 1914 code = ngx_array_push_n(params->lengths, sizeof(uintptr_t)); |
1911 if (code == NULL) { | 1915 if (code == NULL) { |
1912 return NGX_ERROR; | 1916 return NGX_ERROR; |
1913 } | 1917 } |
1914 | 1918 |
1915 *code = (uintptr_t) NULL; | 1919 *code = (uintptr_t) NULL; |
1916 | 1920 |
1917 | 1921 |
1918 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); | 1922 code = ngx_array_push_n(params->values, sizeof(uintptr_t)); |
1919 if (code == NULL) { | 1923 if (code == NULL) { |
1920 return NGX_ERROR; | 1924 return NGX_ERROR; |
1921 } | 1925 } |
1922 | 1926 |
1923 *code = (uintptr_t) NULL; | 1927 *code = (uintptr_t) NULL; |
1924 } | 1928 } |
1925 | 1929 |
1926 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | 1930 code = ngx_array_push_n(params->lengths, sizeof(uintptr_t)); |
1927 if (code == NULL) { | 1931 if (code == NULL) { |
1928 return NGX_ERROR; | 1932 return NGX_ERROR; |
1929 } | 1933 } |
1930 | 1934 |
1931 *code = (uintptr_t) NULL; | 1935 *code = (uintptr_t) NULL; |
1932 | 1936 |
1933 conf->header_params = headers_names.nelts; | 1937 params->number = headers_names.nelts; |
1934 | 1938 |
1935 hash.hash = &conf->headers_hash; | 1939 hash.hash = ¶ms->hash; |
1936 hash.key = ngx_hash_key_lc; | 1940 hash.key = ngx_hash_key_lc; |
1937 hash.max_size = 512; | 1941 hash.max_size = 512; |
1938 hash.bucket_size = 64; | 1942 hash.bucket_size = 64; |
1939 hash.name = "uwsgi_params_hash"; | 1943 hash.name = "uwsgi_params_hash"; |
1940 hash.pool = cf->pool; | 1944 hash.pool = cf->pool; |