Klaus Demo nginx / 5f625b7
Cache: normalization of some Vary headers. Spaces in Accept-Charset, Accept-Encoding, and Accept-Language headers are now ignored. As per syntax of these headers spaces can only appear in places where they are optional. Maxim Dounin 6 years ago
1 changed file(s) with 66 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
950950 ngx_http_file_cache_vary_header(ngx_http_request_t *r, ngx_md5_t *md5,
951951 ngx_str_t *name)
952952 {
953 ngx_uint_t i;
953 size_t len;
954 u_char *p, *start, *last;
955 ngx_uint_t i, multiple, normalize;
954956 ngx_list_part_t *part;
955957 ngx_table_elt_t *header;
958
959 multiple = 0;
960 normalize = 0;
961
962 if (name->len == sizeof("Accept-Charset") - 1
963 && ngx_strncasecmp(name->data, (u_char *) "Accept-Charset",
964 sizeof("Accept-Charset") - 1) == 0)
965 {
966 normalize = 1;
967
968 } else if (name->len == sizeof("Accept-Encoding") - 1
969 && ngx_strncasecmp(name->data, (u_char *) "Accept-Encoding",
970 sizeof("Accept-Encoding") - 1) == 0)
971 {
972 normalize = 1;
973
974 } else if (name->len == sizeof("Accept-Language") - 1
975 && ngx_strncasecmp(name->data, (u_char *) "Accept-Language",
976 sizeof("Accept-Language") - 1) == 0)
977 {
978 normalize = 1;
979 }
956980
957981 part = &r->headers_in.headers.part;
958982 header = part->elts;
9811005 continue;
9821006 }
9831007
984 ngx_md5_update(md5, header[i].value.data, header[i].value.len);
1008 if (!normalize) {
1009
1010 if (multiple) {
1011 ngx_md5_update(md5, (u_char *) ",", sizeof(",") - 1);
1012 }
1013
1014 ngx_md5_update(md5, header[i].value.data, header[i].value.len);
1015
1016 multiple = 1;
1017
1018 continue;
1019 }
1020
1021 /* normalize spaces */
1022
1023 p = header[i].value.data;
1024 start = p;
1025 last = p + header[i].value.len;
1026
1027 while (p < last) {
1028
1029 while (p < last && (*p == ' ' || *p == ',')) { p++; }
1030
1031 start = p;
1032
1033 while (p < last && *p != ',' && *p != ' ') { p++; }
1034
1035 len = p - start;
1036
1037 if (len == 0) {
1038 break;
1039 }
1040
1041 if (multiple) {
1042 ngx_md5_update(md5, (u_char *) ",", sizeof(",") - 1);
1043 }
1044
1045 ngx_md5_update(md5, start, len);
1046
1047 multiple = 1;
1048 }
9851049 }
9861050 }
9871051