comparison src/http/ngx_http_core_module.c @ 8020:f8f6b9fee66a

FastCGI: combining headers with identical names (ticket #1724). FastCGI responder is expected to receive CGI/1.1 environment variables in the parameters (see section "6.2 Responder" of the FastCGI specification). Obviously enough, there cannot be multiple environment variables with the same name. Further, CGI specification (RFC 3875, section "4.1.18. Protocol-Specific Meta-Variables") explicitly requires to combine headers: "If multiple header fields with the same field-name are received then the server MUST rewrite them as a single value having the same semantics".
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 30 May 2022 21:25:27 +0300
parents ae992b5a27b2
children ef6a3a99a81a
comparison
equal deleted inserted replaced
8019:0e562a332529 8020:f8f6b9fee66a
2795 *addr = paddr; 2795 *addr = paddr;
2796 found = 1; 2796 found = 1;
2797 xfflen = p - 1 - xff; 2797 xfflen = p - 1 - xff;
2798 2798
2799 } while (recursive && p > xff); 2799 } while (recursive && p > xff);
2800
2801 return NGX_OK;
2802 }
2803
2804
2805 ngx_int_t
2806 ngx_http_link_multi_headers(ngx_http_request_t *r)
2807 {
2808 ngx_uint_t i, j;
2809 ngx_list_part_t *part, *ppart;
2810 ngx_table_elt_t *header, *pheader, **ph;
2811
2812 if (r->headers_in.multi_linked) {
2813 return NGX_OK;
2814 }
2815
2816 r->headers_in.multi_linked = 1;
2817
2818 part = &r->headers_in.headers.part;
2819 header = part->elts;
2820
2821 for (i = 0; /* void */; i++) {
2822
2823 if (i >= part->nelts) {
2824 if (part->next == NULL) {
2825 break;
2826 }
2827
2828 part = part->next;
2829 header = part->elts;
2830 i = 0;
2831 }
2832
2833 header[i].next = NULL;
2834
2835 /*
2836 * search for previous headers with the same name;
2837 * if there are any, link to them
2838 */
2839
2840 ppart = &r->headers_in.headers.part;
2841 pheader = ppart->elts;
2842
2843 for (j = 0; /* void */; j++) {
2844
2845 if (j >= ppart->nelts) {
2846 if (ppart->next == NULL) {
2847 break;
2848 }
2849
2850 ppart = ppart->next;
2851 pheader = ppart->elts;
2852 j = 0;
2853 }
2854
2855 if (part == ppart && i == j) {
2856 break;
2857 }
2858
2859 if (header[i].key.len == pheader[j].key.len
2860 && ngx_strncasecmp(header[i].key.data, pheader[j].key.data,
2861 header[i].key.len)
2862 == 0)
2863 {
2864 ph = &pheader[j].next;
2865 while (*ph) { ph = &(*ph)->next; }
2866 *ph = &header[i];
2867
2868 r->headers_in.multi = 1;
2869
2870 break;
2871 }
2872 }
2873 }
2800 2874
2801 return NGX_OK; 2875 return NGX_OK;
2802 } 2876 }
2803 2877
2804 2878