Mercurial > hg > nginx-quic
comparison src/http/modules/ngx_http_fastcgi_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 |
---|---|
9 #include <ngx_core.h> | 9 #include <ngx_core.h> |
10 #include <ngx_http.h> | 10 #include <ngx_http.h> |
11 | 11 |
12 | 12 |
13 typedef struct { | 13 typedef struct { |
14 ngx_array_t *flushes; | |
15 ngx_array_t *lengths; | |
16 ngx_array_t *values; | |
17 ngx_uint_t number; | |
18 ngx_hash_t hash; | |
19 } ngx_http_fastcgi_params_t; | |
20 | |
21 | |
22 typedef struct { | |
14 ngx_http_upstream_conf_t upstream; | 23 ngx_http_upstream_conf_t upstream; |
15 | 24 |
16 ngx_str_t index; | 25 ngx_str_t index; |
17 | 26 |
18 ngx_array_t *flushes; | 27 ngx_http_fastcgi_params_t params; |
19 ngx_array_t *params_len; | 28 |
20 ngx_array_t *params; | |
21 ngx_array_t *params_source; | 29 ngx_array_t *params_source; |
22 ngx_array_t *catch_stderr; | 30 ngx_array_t *catch_stderr; |
23 | 31 |
24 ngx_array_t *fastcgi_lengths; | 32 ngx_array_t *fastcgi_lengths; |
25 ngx_array_t *fastcgi_values; | 33 ngx_array_t *fastcgi_values; |
26 | |
27 ngx_hash_t headers_hash; | |
28 ngx_uint_t header_params; | |
29 | 34 |
30 ngx_flag_t keep_conn; | 35 ngx_flag_t keep_conn; |
31 | 36 |
32 #if (NGX_HTTP_CACHE) | 37 #if (NGX_HTTP_CACHE) |
33 ngx_http_complex_value_t cache_key; | 38 ngx_http_complex_value_t cache_key; |
149 static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf); | 154 static ngx_int_t ngx_http_fastcgi_add_variables(ngx_conf_t *cf); |
150 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); | 155 static void *ngx_http_fastcgi_create_loc_conf(ngx_conf_t *cf); |
151 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, | 156 static char *ngx_http_fastcgi_merge_loc_conf(ngx_conf_t *cf, |
152 void *parent, void *child); | 157 void *parent, void *child); |
153 static ngx_int_t ngx_http_fastcgi_init_params(ngx_conf_t *cf, | 158 static ngx_int_t ngx_http_fastcgi_init_params(ngx_conf_t *cf, |
154 ngx_http_fastcgi_loc_conf_t *conf); | 159 ngx_http_fastcgi_loc_conf_t *conf, ngx_http_fastcgi_params_t *params); |
155 | 160 |
156 static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, | 161 static ngx_int_t ngx_http_fastcgi_script_name_variable(ngx_http_request_t *r, |
157 ngx_http_variable_value_t *v, uintptr_t data); | 162 ngx_http_variable_value_t *v, uintptr_t data); |
158 static ngx_int_t ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r, | 163 static ngx_int_t ngx_http_fastcgi_path_info_variable(ngx_http_request_t *r, |
159 ngx_http_variable_value_t *v, uintptr_t data); | 164 ngx_http_variable_value_t *v, uintptr_t data); |
778 ngx_list_part_t *part; | 783 ngx_list_part_t *part; |
779 ngx_table_elt_t *header, **ignored; | 784 ngx_table_elt_t *header, **ignored; |
780 ngx_http_script_code_pt code; | 785 ngx_http_script_code_pt code; |
781 ngx_http_script_engine_t e, le; | 786 ngx_http_script_engine_t e, le; |
782 ngx_http_fastcgi_header_t *h; | 787 ngx_http_fastcgi_header_t *h; |
788 ngx_http_fastcgi_params_t *params; | |
783 ngx_http_fastcgi_loc_conf_t *flcf; | 789 ngx_http_fastcgi_loc_conf_t *flcf; |
784 ngx_http_script_len_code_pt lcode; | 790 ngx_http_script_len_code_pt lcode; |
785 | 791 |
786 len = 0; | 792 len = 0; |
787 header_params = 0; | 793 header_params = 0; |
788 ignored = NULL; | 794 ignored = NULL; |
789 | 795 |
790 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module); | 796 flcf = ngx_http_get_module_loc_conf(r, ngx_http_fastcgi_module); |
791 | 797 |
792 if (flcf->params_len) { | 798 params = &flcf->params; |
799 | |
800 if (params->lengths) { | |
793 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); | 801 ngx_memzero(&le, sizeof(ngx_http_script_engine_t)); |
794 | 802 |
795 ngx_http_script_flush_no_cacheable_variables(r, flcf->flushes); | 803 ngx_http_script_flush_no_cacheable_variables(r, params->flushes); |
796 le.flushed = 1; | 804 le.flushed = 1; |
797 | 805 |
798 le.ip = flcf->params_len->elts; | 806 le.ip = params->lengths->elts; |
799 le.request = r; | 807 le.request = r; |
800 | 808 |
801 while (*(uintptr_t *) le.ip) { | 809 while (*(uintptr_t *) le.ip) { |
802 | 810 |
803 lcode = *(ngx_http_script_len_code_pt *) le.ip; | 811 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
822 if (flcf->upstream.pass_request_headers) { | 830 if (flcf->upstream.pass_request_headers) { |
823 | 831 |
824 allocated = 0; | 832 allocated = 0; |
825 lowcase_key = NULL; | 833 lowcase_key = NULL; |
826 | 834 |
827 if (flcf->header_params) { | 835 if (params->number) { |
828 n = 0; | 836 n = 0; |
829 part = &r->headers_in.headers.part; | 837 part = &r->headers_in.headers.part; |
830 | 838 |
831 while (part) { | 839 while (part) { |
832 n += part->nelts; | 840 n += part->nelts; |
852 part = part->next; | 860 part = part->next; |
853 header = part->elts; | 861 header = part->elts; |
854 i = 0; | 862 i = 0; |
855 } | 863 } |
856 | 864 |
857 if (flcf->header_params) { | 865 if (params->number) { |
858 if (allocated < header[i].key.len) { | 866 if (allocated < header[i].key.len) { |
859 allocated = header[i].key.len + 16; | 867 allocated = header[i].key.len + 16; |
860 lowcase_key = ngx_pnalloc(r->pool, allocated); | 868 lowcase_key = ngx_pnalloc(r->pool, allocated); |
861 if (lowcase_key == NULL) { | 869 if (lowcase_key == NULL) { |
862 return NGX_ERROR; | 870 return NGX_ERROR; |
877 | 885 |
878 hash = ngx_hash(hash, ch); | 886 hash = ngx_hash(hash, ch); |
879 lowcase_key[n] = ch; | 887 lowcase_key[n] = ch; |
880 } | 888 } |
881 | 889 |
882 if (ngx_hash_find(&flcf->headers_hash, hash, lowcase_key, n)) { | 890 if (ngx_hash_find(¶ms->hash, hash, lowcase_key, n)) { |
883 ignored[header_params++] = &header[i]; | 891 ignored[header_params++] = &header[i]; |
884 continue; | 892 continue; |
885 } | 893 } |
886 | 894 |
887 n += sizeof("HTTP_") - 1; | 895 n += sizeof("HTTP_") - 1; |
947 b->last = b->pos + sizeof(ngx_http_fastcgi_header_t) | 955 b->last = b->pos + sizeof(ngx_http_fastcgi_header_t) |
948 + sizeof(ngx_http_fastcgi_begin_request_t) | 956 + sizeof(ngx_http_fastcgi_begin_request_t) |
949 + sizeof(ngx_http_fastcgi_header_t); | 957 + sizeof(ngx_http_fastcgi_header_t); |
950 | 958 |
951 | 959 |
952 if (flcf->params_len) { | 960 if (params->lengths) { |
953 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); | 961 ngx_memzero(&e, sizeof(ngx_http_script_engine_t)); |
954 | 962 |
955 e.ip = flcf->params->elts; | 963 e.ip = params->values->elts; |
956 e.pos = b->last; | 964 e.pos = b->last; |
957 e.request = r; | 965 e.request = r; |
958 e.flushed = 1; | 966 e.flushed = 1; |
959 | 967 |
960 le.ip = flcf->params_len->elts; | 968 le.ip = params->lengths->elts; |
961 | 969 |
962 while (*(uintptr_t *) le.ip) { | 970 while (*(uintptr_t *) le.ip) { |
963 | 971 |
964 lcode = *(ngx_http_script_len_code_pt *) le.ip; | 972 lcode = *(ngx_http_script_len_code_pt *) le.ip; |
965 key_len = (u_char) lcode(&le); | 973 key_len = (u_char) lcode(&le); |
2708 | 2716 |
2709 #if (NGX_HTTP_CACHE) | 2717 #if (NGX_HTTP_CACHE) |
2710 if ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL)) | 2718 if ((conf->upstream.cache == NULL) == (prev->upstream.cache == NULL)) |
2711 #endif | 2719 #endif |
2712 { | 2720 { |
2713 conf->flushes = prev->flushes; | |
2714 conf->params_len = prev->params_len; | |
2715 conf->params = prev->params; | 2721 conf->params = prev->params; |
2716 conf->headers_hash = prev->headers_hash; | 2722 } |
2717 conf->header_params = prev->header_params; | 2723 } |
2718 } | 2724 |
2719 } | 2725 if (ngx_http_fastcgi_init_params(cf, conf, &conf->params) != NGX_OK) { |
2720 | |
2721 if (ngx_http_fastcgi_init_params(cf, conf) != NGX_OK) { | |
2722 return NGX_CONF_ERROR; | 2726 return NGX_CONF_ERROR; |
2723 } | 2727 } |
2724 | 2728 |
2725 return NGX_CONF_OK; | 2729 return NGX_CONF_OK; |
2726 } | 2730 } |
2727 | 2731 |
2728 | 2732 |
2729 static ngx_int_t | 2733 static ngx_int_t |
2730 ngx_http_fastcgi_init_params(ngx_conf_t *cf, ngx_http_fastcgi_loc_conf_t *conf) | 2734 ngx_http_fastcgi_init_params(ngx_conf_t *cf, ngx_http_fastcgi_loc_conf_t *conf, |
2735 ngx_http_fastcgi_params_t *params) | |
2731 { | 2736 { |
2732 u_char *p; | 2737 u_char *p; |
2733 size_t size; | 2738 size_t size; |
2734 uintptr_t *code; | 2739 uintptr_t *code; |
2735 ngx_uint_t i, nsrc; | 2740 ngx_uint_t i, nsrc; |
2741 ngx_hash_init_t hash; | 2746 ngx_hash_init_t hash; |
2742 ngx_http_upstream_param_t *src; | 2747 ngx_http_upstream_param_t *src; |
2743 ngx_http_script_compile_t sc; | 2748 ngx_http_script_compile_t sc; |
2744 ngx_http_script_copy_code_t *copy; | 2749 ngx_http_script_copy_code_t *copy; |
2745 | 2750 |
2746 if (conf->headers_hash.buckets) { | 2751 if (params->hash.buckets) { |
2747 return NGX_OK; | 2752 return NGX_OK; |
2748 } | 2753 } |
2749 | 2754 |
2750 if (conf->params_source == NULL | 2755 if (conf->params_source == NULL |
2751 #if (NGX_HTTP_CACHE) | 2756 #if (NGX_HTTP_CACHE) |
2752 && (conf->upstream.cache == NULL) | 2757 && (conf->upstream.cache == NULL) |
2753 #endif | 2758 #endif |
2754 ) | 2759 ) |
2755 { | 2760 { |
2756 conf->headers_hash.buckets = (void *) 1; | 2761 params->hash.buckets = (void *) 1; |
2757 return NGX_OK; | 2762 return NGX_OK; |
2758 } | 2763 } |
2759 | 2764 |
2760 conf->params_len = ngx_array_create(cf->pool, 64, 1); | 2765 params->lengths = ngx_array_create(cf->pool, 64, 1); |
2761 if (conf->params_len == NULL) { | 2766 if (params->lengths == NULL) { |
2762 return NGX_ERROR; | 2767 return NGX_ERROR; |
2763 } | 2768 } |
2764 | 2769 |
2765 conf->params = ngx_array_create(cf->pool, 512, 1); | 2770 params->values = ngx_array_create(cf->pool, 512, 1); |
2766 if (conf->params == NULL) { | 2771 if (params->values == NULL) { |
2767 return NGX_ERROR; | 2772 return NGX_ERROR; |
2768 } | 2773 } |
2769 | 2774 |
2770 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) | 2775 if (ngx_array_init(&headers_names, cf->temp_pool, 4, sizeof(ngx_hash_key_t)) |
2771 != NGX_OK) | 2776 != NGX_OK) |
2856 if (src[i].value.len == 0) { | 2861 if (src[i].value.len == 0) { |
2857 continue; | 2862 continue; |
2858 } | 2863 } |
2859 } | 2864 } |
2860 | 2865 |
2861 copy = ngx_array_push_n(conf->params_len, | 2866 copy = ngx_array_push_n(params->lengths, |
2862 sizeof(ngx_http_script_copy_code_t)); | 2867 sizeof(ngx_http_script_copy_code_t)); |
2863 if (copy == NULL) { | 2868 if (copy == NULL) { |
2864 return NGX_ERROR; | 2869 return NGX_ERROR; |
2865 } | 2870 } |
2866 | 2871 |
2867 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; | 2872 copy->code = (ngx_http_script_code_pt) ngx_http_script_copy_len_code; |
2868 copy->len = src[i].key.len; | 2873 copy->len = src[i].key.len; |
2869 | 2874 |
2870 copy = ngx_array_push_n(conf->params_len, | 2875 copy = ngx_array_push_n(params->lengths, |
2871 sizeof(ngx_http_script_copy_code_t)); | 2876 sizeof(ngx_http_script_copy_code_t)); |
2872 if (copy == NULL) { | 2877 if (copy == NULL) { |
2873 return NGX_ERROR; | 2878 return NGX_ERROR; |
2874 } | 2879 } |
2875 | 2880 |
2879 | 2884 |
2880 size = (sizeof(ngx_http_script_copy_code_t) | 2885 size = (sizeof(ngx_http_script_copy_code_t) |
2881 + src[i].key.len + sizeof(uintptr_t) - 1) | 2886 + src[i].key.len + sizeof(uintptr_t) - 1) |
2882 & ~(sizeof(uintptr_t) - 1); | 2887 & ~(sizeof(uintptr_t) - 1); |
2883 | 2888 |
2884 copy = ngx_array_push_n(conf->params, size); | 2889 copy = ngx_array_push_n(params->values, size); |
2885 if (copy == NULL) { | 2890 if (copy == NULL) { |
2886 return NGX_ERROR; | 2891 return NGX_ERROR; |
2887 } | 2892 } |
2888 | 2893 |
2889 copy->code = ngx_http_script_copy_code; | 2894 copy->code = ngx_http_script_copy_code; |
2895 | 2900 |
2896 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); | 2901 ngx_memzero(&sc, sizeof(ngx_http_script_compile_t)); |
2897 | 2902 |
2898 sc.cf = cf; | 2903 sc.cf = cf; |
2899 sc.source = &src[i].value; | 2904 sc.source = &src[i].value; |
2900 sc.flushes = &conf->flushes; | 2905 sc.flushes = ¶ms->flushes; |
2901 sc.lengths = &conf->params_len; | 2906 sc.lengths = ¶ms->lengths; |
2902 sc.values = &conf->params; | 2907 sc.values = ¶ms->values; |
2903 | 2908 |
2904 if (ngx_http_script_compile(&sc) != NGX_OK) { | 2909 if (ngx_http_script_compile(&sc) != NGX_OK) { |
2905 return NGX_ERROR; | 2910 return NGX_ERROR; |
2906 } | 2911 } |
2907 | 2912 |
2908 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | 2913 code = ngx_array_push_n(params->lengths, sizeof(uintptr_t)); |
2909 if (code == NULL) { | 2914 if (code == NULL) { |
2910 return NGX_ERROR; | 2915 return NGX_ERROR; |
2911 } | 2916 } |
2912 | 2917 |
2913 *code = (uintptr_t) NULL; | 2918 *code = (uintptr_t) NULL; |
2914 | 2919 |
2915 | 2920 |
2916 code = ngx_array_push_n(conf->params, sizeof(uintptr_t)); | 2921 code = ngx_array_push_n(params->values, sizeof(uintptr_t)); |
2917 if (code == NULL) { | 2922 if (code == NULL) { |
2918 return NGX_ERROR; | 2923 return NGX_ERROR; |
2919 } | 2924 } |
2920 | 2925 |
2921 *code = (uintptr_t) NULL; | 2926 *code = (uintptr_t) NULL; |
2922 } | 2927 } |
2923 | 2928 |
2924 code = ngx_array_push_n(conf->params_len, sizeof(uintptr_t)); | 2929 code = ngx_array_push_n(params->lengths, sizeof(uintptr_t)); |
2925 if (code == NULL) { | 2930 if (code == NULL) { |
2926 return NGX_ERROR; | 2931 return NGX_ERROR; |
2927 } | 2932 } |
2928 | 2933 |
2929 *code = (uintptr_t) NULL; | 2934 *code = (uintptr_t) NULL; |
2930 | 2935 |
2931 conf->header_params = headers_names.nelts; | 2936 params->number = headers_names.nelts; |
2932 | 2937 |
2933 hash.hash = &conf->headers_hash; | 2938 hash.hash = ¶ms->hash; |
2934 hash.key = ngx_hash_key_lc; | 2939 hash.key = ngx_hash_key_lc; |
2935 hash.max_size = 512; | 2940 hash.max_size = 512; |
2936 hash.bucket_size = 64; | 2941 hash.bucket_size = 64; |
2937 hash.name = "fastcgi_params_hash"; | 2942 hash.name = "fastcgi_params_hash"; |
2938 hash.pool = cf->pool; | 2943 hash.pool = cf->pool; |