comparison src/http/ngx_http_parse.c @ 8024:ef6a3a99a81a

Reworked multi headers to use linked lists. Multi headers are now using linked lists instead of arrays. Notably, the following fields were changed: r->headers_in.cookies (renamed to r->headers_in.cookie), r->headers_in.x_forwarded_for, r->headers_out.cache_control, r->headers_out.link, u->headers_in.cache_control u->headers_in.cookies (renamed to u->headers_in.set_cookie). The r->headers_in.cookies and u->headers_in.cookies fields were renamed to r->headers_in.cookie and u->headers_in.set_cookie to match header names. The ngx_http_parse_multi_header_lines() and ngx_http_parse_set_cookie_lines() functions were changed accordingly. With this change, multi headers are now essentially equivalent to normal headers, and following changes will further make them equivalent.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 30 May 2022 21:25:33 +0300
parents b87b7092cedb
children 8d0753760546
comparison
equal deleted inserted replaced
8023:08b3ea81ff5f 8024:ef6a3a99a81a
1958 1958
1959 return NGX_ERROR; 1959 return NGX_ERROR;
1960 } 1960 }
1961 1961
1962 1962
1963 ngx_int_t 1963 ngx_table_elt_t *
1964 ngx_http_parse_multi_header_lines(ngx_array_t *headers, ngx_str_t *name, 1964 ngx_http_parse_multi_header_lines(ngx_http_request_t *r,
1965 ngx_str_t *value) 1965 ngx_table_elt_t *headers, ngx_str_t *name, ngx_str_t *value)
1966 { 1966 {
1967 ngx_uint_t i; 1967 u_char *start, *last, *end, ch;
1968 u_char *start, *last, *end, ch; 1968 ngx_table_elt_t *h;
1969 ngx_table_elt_t **h; 1969
1970 1970 for (h = headers; h; h = h->next) {
1971 h = headers->elts; 1971
1972 1972 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1973 for (i = 0; i < headers->nelts; i++) { 1973 "parse header: \"%V: %V\"", &h->key, &h->value);
1974 1974
1975 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, headers->pool->log, 0, 1975 if (name->len > h->value.len) {
1976 "parse header: \"%V: %V\"", &h[i]->key, &h[i]->value);
1977
1978 if (name->len > h[i]->value.len) {
1979 continue; 1976 continue;
1980 } 1977 }
1981 1978
1982 start = h[i]->value.data; 1979 start = h->value.data;
1983 end = h[i]->value.data + h[i]->value.len; 1980 end = h->value.data + h->value.len;
1984 1981
1985 while (start < end) { 1982 while (start < end) {
1986 1983
1987 if (ngx_strncasecmp(start, name->data, name->len) != 0) { 1984 if (ngx_strncasecmp(start, name->data, name->len) != 0) {
1988 goto skip; 1985 goto skip;
1992 /* void */ 1989 /* void */
1993 } 1990 }
1994 1991
1995 if (value == NULL) { 1992 if (value == NULL) {
1996 if (start == end || *start == ',') { 1993 if (start == end || *start == ',') {
1997 return i; 1994 return h;
1998 } 1995 }
1999 1996
2000 goto skip; 1997 goto skip;
2001 } 1998 }
2002 1999
2012 } 2009 }
2013 2010
2014 value->len = last - start; 2011 value->len = last - start;
2015 value->data = start; 2012 value->data = start;
2016 2013
2017 return i; 2014 return h;
2018 2015
2019 skip: 2016 skip:
2020 2017
2021 while (start < end) { 2018 while (start < end) {
2022 ch = *start++; 2019 ch = *start++;
2027 2024
2028 while (start < end && *start == ' ') { start++; } 2025 while (start < end && *start == ' ') { start++; }
2029 } 2026 }
2030 } 2027 }
2031 2028
2032 return NGX_DECLINED; 2029 return NULL;
2033 } 2030 }
2034 2031
2035 2032
2036 ngx_int_t 2033 ngx_table_elt_t *
2037 ngx_http_parse_set_cookie_lines(ngx_array_t *headers, ngx_str_t *name, 2034 ngx_http_parse_set_cookie_lines(ngx_http_request_t *r,
2038 ngx_str_t *value) 2035 ngx_table_elt_t *headers, ngx_str_t *name, ngx_str_t *value)
2039 { 2036 {
2040 ngx_uint_t i; 2037 u_char *start, *last, *end;
2041 u_char *start, *last, *end; 2038 ngx_table_elt_t *h;
2042 ngx_table_elt_t **h; 2039
2043 2040 for (h = headers; h; h = h->next) {
2044 h = headers->elts; 2041
2045 2042 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
2046 for (i = 0; i < headers->nelts; i++) { 2043 "parse header: \"%V: %V\"", &h->key, &h->value);
2047 2044
2048 ngx_log_debug2(NGX_LOG_DEBUG_HTTP, headers->pool->log, 0, 2045 if (name->len >= h->value.len) {
2049 "parse header: \"%V: %V\"", &h[i]->key, &h[i]->value);
2050
2051 if (name->len >= h[i]->value.len) {
2052 continue; 2046 continue;
2053 } 2047 }
2054 2048
2055 start = h[i]->value.data; 2049 start = h->value.data;
2056 end = h[i]->value.data + h[i]->value.len; 2050 end = h->value.data + h->value.len;
2057 2051
2058 if (ngx_strncasecmp(start, name->data, name->len) != 0) { 2052 if (ngx_strncasecmp(start, name->data, name->len) != 0) {
2059 continue; 2053 continue;
2060 } 2054 }
2061 2055
2075 } 2069 }
2076 2070
2077 value->len = last - start; 2071 value->len = last - start;
2078 value->data = start; 2072 value->data = start;
2079 2073
2080 return i; 2074 return h;
2081 } 2075 }
2082 2076
2083 return NGX_DECLINED; 2077 return NULL;
2084 } 2078 }
2085 2079
2086 2080
2087 ngx_int_t 2081 ngx_int_t
2088 ngx_http_arg(ngx_http_request_t *r, u_char *name, size_t len, ngx_str_t *value) 2082 ngx_http_arg(ngx_http_request_t *r, u_char *name, size_t len, ngx_str_t *value)