| 1 |
|
| /* punk_accept.h - Accept negotiation for $c->respond_to, in C. |
| 2 |
|
| * |
| 3 |
|
| * A small RFC 9110 media-range parser: no regex engine, no allocation - the |
| 4 |
|
| * ranges point into the header's own buffer. Enough Accept to be correct |
| 5 |
|
| * about the two things naive matching gets wrong: q-values order the |
| 6 |
|
| * browser's `text/html,application/xml;q=0.9,* / *;q=0.8` correctly, and |
| 7 |
|
| * `q=0` excludes rather than matches. |
| 8 |
|
| * |
| 9 |
|
| * Include after punk_response.h; xs/context.xs is the consumer. |
| 10 |
|
| */ |
| 11 |
|
| |
| 12 |
|
| #ifndef PUNK_ACCEPT_H |
| 13 |
|
| #define PUNK_ACCEPT_H |
| 14 |
|
| |
| 15 |
|
| #define PA_RANGE_MAX 32 |
| 16 |
|
| |
| 17 |
|
| typedef struct pa_range { |
| 18 |
|
| const char *t; STRLEN tl; /* type, pointing into the header */ |
| 19 |
|
| const char *s; STRLEN sl; /* subtype, pointing into the header */ |
| 20 |
|
| int q; /* per mille: 0..1000 */ |
| 21 |
|
| } pa_range; |
| 22 |
|
| |
| 23 |
655 |
▶ | static int pa_ws(char c) { return c == ' ' || c == '\t'; } /* # uncoverable condition left count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| static int pa_ws(char c) { return c == ' ' || c == '\t'; } /* # uncoverable condition left count:2 class:ignore_covered_err */ |
649 |
6 |
655 |
| static int pa_ws(char c) { return c == ' ' || c == '\t'; } /* # uncoverable condition left count:2 class:ignore_covered_err */ |
0 |
649 |
649 |
|
| 24 |
|
| |
| 25 |
|
| /* the q of one parameter list: ";q=0.8" -> 800; absent or malformed -> 1000 */ |
| 26 |
265 |
| static int pa_q_of(const char *p, const char *end) { |
| 27 |
265 |
▶ | while (p < end) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < end) { |
19 |
246 |
265 |
|
| 28 |
|
| /* |
| 29 |
|
| # uncoverable branch true count:2 |
| 30 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 31 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 32 |
39 |
▶ | while (p < end && (pa_ws(*p) || *p == ';')) p++; |
Branch: 3 branches
| Branch | True | False | Total |
| while (p < end && (pa_ws(*p) || *p == ';')) p++; |
39 |
0 |
39 |
| while (p < end && (pa_ws(*p) || *p == ';')) p++; |
0 |
39 |
39 |
| while (p < end && (pa_ws(*p) || *p == ';')) p++; |
20 |
19 |
39 |
|
| 33 |
|
| /* |
| 34 |
|
| # uncoverable branch false |
| 35 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 36 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 37 |
|
| # uncoverable condition left count:3 class:ignore_covered_err |
| 38 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 39 |
19 |
▶ | if (p + 1 < end && (*p == 'q' || *p == 'Q')) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (p + 1 < end && (*p == 'q' || *p == 'Q')) { |
19 |
0 |
19 |
| if (p + 1 < end && (*p == 'q' || *p == 'Q')) { |
0 |
19 |
19 |
| if (p + 1 < end && (*p == 'q' || *p == 'Q')) { |
0 |
0 |
0 |
|
| 40 |
19 |
| const char *v = p + 1; |
| 41 |
|
| /* |
| 42 |
|
| # uncoverable branch true class:ignore_covered_err |
| 43 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 44 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 45 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 46 |
19 |
▶ | while (v < end && pa_ws(*v)) v++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (v < end && pa_ws(*v)) v++; |
19 |
0 |
19 |
| while (v < end && pa_ws(*v)) v++; |
0 |
19 |
19 |
|
| 47 |
|
| /* |
| 48 |
|
| # uncoverable branch false |
| 49 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 50 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 51 |
19 |
▶ | if (v < end && *v == '=') { |
Branch: 2 branches
| Branch | True | False | Total |
| if (v < end && *v == '=') { |
19 |
0 |
19 |
| if (v < end && *v == '=') { |
19 |
0 |
19 |
|
| 52 |
|
| int q; |
| 53 |
19 |
| v++; |
| 54 |
|
| /* |
| 55 |
|
| # uncoverable branch true class:ignore_covered_err |
| 56 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 57 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 58 |
19 |
▶ | while (v < end && pa_ws(*v)) v++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (v < end && pa_ws(*v)) v++; |
17 |
2 |
19 |
| while (v < end && pa_ws(*v)) v++; |
0 |
17 |
17 |
|
| 59 |
19 |
▶ | if (v >= end) return 1000; |
Branch: 1 branch
| Branch | True | False | Total |
| if (v >= end) return 1000; |
2 |
17 |
19 |
|
| 60 |
|
| /* |
| 61 |
|
| # uncoverable branch true |
| 62 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 63 |
17 |
▶ | if (*v == '1') return 1000; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*v == '1') return 1000; |
0 |
17 |
17 |
|
| 64 |
17 |
▶ | if (*v != '0') return 1000; |
Branch: 1 branch
| Branch | True | False | Total |
| if (*v != '0') return 1000; |
1 |
16 |
17 |
|
| 65 |
16 |
| q = 0; v++; |
| 66 |
16 |
▶ | if (v < end && *v == '.') { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (v < end && *v == '.') { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
12 |
4 |
16 |
| if (v < end && *v == '.') { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
12 |
0 |
12 |
|
| 67 |
12 |
| int place = 100; |
| 68 |
12 |
| v++; |
| 69 |
|
| /* |
| 70 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 71 |
|
| # uncoverable condition right count:3 class:ignore_covered_err |
| 72 |
|
| # uncoverable condition right count:4 class:ignore_covered_err */ |
| 73 |
24 |
▶ | while (v < end && *v >= '0' && *v <= '9' && place) { |
Branch: 4 branches
| Branch | True | False | Total |
| while (v < end && *v >= '0' && *v <= '9' && place) { |
12 |
12 |
24 |
| while (v < end && *v >= '0' && *v <= '9' && place) { |
12 |
0 |
12 |
| while (v < end && *v >= '0' && *v <= '9' && place) { |
12 |
0 |
12 |
| while (v < end && *v >= '0' && *v <= '9' && place) { |
12 |
0 |
12 |
|
| 74 |
12 |
| q += (*v - '0') * place; |
| 75 |
12 |
| place /= 10; v++; |
| 76 |
|
| } |
| 77 |
|
| } |
| 78 |
16 |
| return q; |
| 79 |
|
| } |
| 80 |
|
| } |
| 81 |
|
| /* |
| 82 |
|
| # uncoverable statement |
| 83 |
|
| # uncoverable branch true |
| 84 |
|
| # uncoverable branch false |
| 85 |
|
| # uncoverable condition left count:1 |
| 86 |
|
| # uncoverable condition right count:1 |
| 87 |
|
| # uncoverable condition left count:2 |
| 88 |
|
| # uncoverable condition right count:2 */ |
| 89 |
0 |
▶ | while (p < end && *p != ';') p++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && *p != ';') p++; |
0 |
0 |
0 |
| while (p < end && *p != ';') p++; |
0 |
0 |
0 |
|
| 90 |
|
| } |
| 91 |
246 |
| return 1000; |
| 92 |
|
| } |
| 93 |
|
| |
| 94 |
|
| /* Split an Accept value into media ranges. Returns how many were kept; |
| 95 |
|
| * anything past PA_RANGE_MAX or with no shape is ignored, never fatal - |
| 96 |
|
| * a malformed Accept from a client must not be able to error a response. */ |
| 97 |
41 |
| static int pa_parse(const char *a, STRLEN al, pa_range *out, int max) { |
| 98 |
41 |
| const char *p = a, *end = a + al; |
| 99 |
41 |
| int n = 0; |
| 100 |
90 |
▶ | while (p < end && n < max) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < end && n < max) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
49 |
41 |
90 |
| while (p < end && n < max) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
49 |
0 |
49 |
|
| 101 |
49 |
| const char *seg_end = p, *slash, *sub_end, *par; |
| 102 |
724 |
▶ | while (seg_end < end && *seg_end != ',') seg_end++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (seg_end < end && *seg_end != ',') seg_end++; |
683 |
41 |
724 |
| while (seg_end < end && *seg_end != ',') seg_end++; |
675 |
8 |
683 |
|
| 103 |
50 |
▶ | while (p < seg_end && pa_ws(*p)) p++; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| while (p < seg_end && pa_ws(*p)) p++; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
50 |
0 |
50 |
| while (p < seg_end && pa_ws(*p)) p++; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
1 |
49 |
50 |
|
| 104 |
49 |
| par = p; |
| 105 |
683 |
▶ | while (par < seg_end && *par != ';') par++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (par < seg_end && *par != ';') par++; |
641 |
42 |
683 |
| while (par < seg_end && *par != ';') par++; |
634 |
7 |
641 |
|
| 106 |
49 |
| sub_end = par; |
| 107 |
|
| /* |
| 108 |
|
| # uncoverable branch true class:ignore_covered_err |
| 109 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 110 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 111 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 112 |
49 |
▶ | while (sub_end > p && pa_ws(sub_end[-1])) sub_end--; |
Branch: 2 branches
| Branch | True | False | Total |
| while (sub_end > p && pa_ws(sub_end[-1])) sub_end--; |
49 |
0 |
49 |
| while (sub_end > p && pa_ws(sub_end[-1])) sub_end--; |
0 |
49 |
49 |
|
| 113 |
49 |
| slash = p; |
| 114 |
442 |
▶ | while (slash < sub_end && *slash != '/') slash++; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| while (slash < sub_end && *slash != '/') slash++; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
442 |
0 |
442 |
| while (slash < sub_end && *slash != '/') slash++; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
393 |
49 |
442 |
|
| 115 |
|
| /* |
| 116 |
|
| # uncoverable branch false |
| 117 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 118 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 119 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 120 |
49 |
▶ | if (slash < sub_end && slash > p && sub_end > slash + 1) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (slash < sub_end && slash > p && sub_end > slash + 1) { |
49 |
0 |
49 |
| if (slash < sub_end && slash > p && sub_end > slash + 1) { |
49 |
0 |
49 |
| if (slash < sub_end && slash > p && sub_end > slash + 1) { |
49 |
0 |
49 |
|
| 121 |
49 |
| out[n].t = p; out[n].tl = (STRLEN)(slash - p); |
| 122 |
49 |
| out[n].s = slash + 1; out[n].sl = (STRLEN)(sub_end - slash - 1); |
| 123 |
49 |
| out[n].q = pa_q_of(par, seg_end); |
| 124 |
49 |
| n++; |
| 125 |
|
| } |
| 126 |
|
| /* |
| 127 |
|
| # uncoverable statement |
| 128 |
|
| # uncoverable branch true |
| 129 |
|
| # uncoverable branch false |
| 130 |
|
| # uncoverable condition left count:1 |
| 131 |
|
| # uncoverable condition right count:1 |
| 132 |
|
| # uncoverable condition left count:2 |
| 133 |
|
| # uncoverable condition right count:2 */ |
| 134 |
0 |
▶ | else if (sub_end == p + 1 && *p == '*') { /* a bare '*' is '* / *' */ |
Branch: 2 branches
| Branch | True | False | Total |
| else if (sub_end == p + 1 && *p == '*') { /* a bare '*' is '* / *' */ |
0 |
0 |
0 |
| else if (sub_end == p + 1 && *p == '*') { /* a bare '*' is '* / *' */ |
0 |
0 |
0 |
|
| 135 |
0 |
| out[n].t = p; out[n].tl = 1; /* # uncoverable statement */ |
| 136 |
0 |
| out[n].s = p; out[n].sl = 1; /* # uncoverable statement */ |
| 137 |
0 |
| out[n].q = pa_q_of(par, seg_end); /* # uncoverable statement */ |
| 138 |
0 |
| n++; /* # uncoverable statement */ |
| 139 |
|
| } |
| 140 |
49 |
| p = seg_end + 1; |
| 141 |
|
| } |
| 142 |
41 |
| return n; |
| 143 |
|
| } |
| 144 |
|
| |
| 145 |
115 |
▶ | static int pa_star(const char *s, STRLEN l) { return l == 1 && *s == '*'; } /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| static int pa_star(const char *s, STRLEN l) { return l == 1 && *s == '*'; } /* # uncoverable condition right count:2 class:ignore_covered_err */ |
10 |
105 |
115 |
| static int pa_star(const char *s, STRLEN l) { return l == 1 && *s == '*'; } /* # uncoverable condition right count:2 class:ignore_covered_err */ |
10 |
0 |
10 |
|
| 146 |
|
| |
| 147 |
|
| /* How well the ranges accept one media type: returns the specificity of the |
| 148 |
|
| * most specific matching range (2 exact, 1 type / *, 0 * / *, -1 none), and |
| 149 |
|
| * through q/order that range's q-value and position. RFC 9110's rule: the |
| 150 |
|
| * most specific match decides the q, and q=0 is an exclusion (reported as a |
| 151 |
|
| * match with *q 0, so the caller can tell "refused" from "unmentioned"). */ |
| 152 |
61 |
| static int pa_match(pTHX_ const pa_range *r, int n, |
| 153 |
|
| const char *t, STRLEN tl, const char *s, STRLEN sl, |
| 154 |
|
| int *q, int *order) { |
| 155 |
61 |
| int i, spec = -1; |
| 156 |
138 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
77 |
61 |
138 |
|
| 157 |
|
| int this_spec; |
| 158 |
77 |
▶ | if (pa_star(r[i].t, r[i].tl)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (pa_star(r[i].t, r[i].tl)) |
10 |
67 |
77 |
|
| 159 |
10 |
| this_spec = 0; |
| 160 |
67 |
▶ | else if (r[i].tl == tl && foldEQ(r[i].t, t, (I32)tl)) /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| else if (r[i].tl == tl && foldEQ(r[i].t, t, (I32)tl)) /* # uncoverable condition right count:2 class:ignore_covered_err */ |
38 |
29 |
67 |
| else if (r[i].tl == tl && foldEQ(r[i].t, t, (I32)tl)) /* # uncoverable condition right count:2 class:ignore_covered_err */ |
38 |
0 |
38 |
|
| 161 |
76 |
| this_spec = pa_star(r[i].s, r[i].sl) ? 1 |
| 162 |
101 |
▶ | : (r[i].sl == sl && foldEQ(r[i].s, s, (I32)sl)) ? 2 |
Branch: 2 branches
| Branch | True | False | Total |
| : (r[i].sl == sl && foldEQ(r[i].s, s, (I32)sl)) ? 2 |
38 |
0 |
38 |
| : (r[i].sl == sl && foldEQ(r[i].s, s, (I32)sl)) ? 2 |
25 |
0 |
25 |
|
| 163 |
63 |
▶ | : -1; |
Branch: 1 branch
| Branch | True | False | Total |
| : -1; |
25 |
13 |
38 |
|
| 164 |
|
| else |
| 165 |
29 |
| this_spec = -1; |
| 166 |
77 |
▶ | if (this_spec > spec) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (this_spec > spec) { |
32 |
45 |
77 |
|
| 167 |
32 |
| spec = this_spec; |
| 168 |
32 |
| *q = r[i].q; |
| 169 |
32 |
| *order = i; |
| 170 |
|
| } |
| 171 |
|
| } |
| 172 |
61 |
| return spec; |
| 173 |
|
| } |
| 174 |
|
| |
| 175 |
|
| /* The media type a respond_to format name means. A name with a '/' is taken |
| 176 |
|
| * literally; the short names cover what an application negotiates in |
| 177 |
|
| * practice. Returns 0 for a name it does not know. */ |
| 178 |
61 |
| static int pa_fmt_mime(const char *name, STRLEN nl, |
| 179 |
|
| const char **t, STRLEN *tl, |
| 180 |
|
| const char **s, STRLEN *sl) { |
| 181 |
61 |
| const char *slash = (const char *)memchr(name, '/', nl); |
| 182 |
|
| /* |
| 183 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 184 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 185 |
61 |
▶ | if (slash && slash > name && (STRLEN)(slash - name) < nl - 1) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (slash && slash > name && (STRLEN)(slash - name) < nl - 1) { |
18 |
43 |
61 |
| if (slash && slash > name && (STRLEN)(slash - name) < nl - 1) { |
18 |
0 |
18 |
| if (slash && slash > name && (STRLEN)(slash - name) < nl - 1) { |
18 |
0 |
18 |
|
| 186 |
18 |
| *t = name; *tl = (STRLEN)(slash - name); |
| 187 |
18 |
| *s = slash + 1; *sl = nl - *tl - 1; |
| 188 |
18 |
| return 1; |
| 189 |
|
| } |
| 190 |
43 |
▶ | if (nl == 4 && memEQ(name, "json", 4)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (nl == 4 && memEQ(name, "json", 4)) { |
35 |
8 |
43 |
| if (nl == 4 && memEQ(name, "json", 4)) { |
23 |
12 |
35 |
|
| 191 |
23 |
| *t = "application"; *tl = 11; *s = "json"; *sl = 4; return 1; |
| 192 |
|
| } |
| 193 |
20 |
▶ | if (nl == 4 && memEQ(name, "html", 4)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (nl == 4 && memEQ(name, "html", 4)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
12 |
8 |
20 |
| if (nl == 4 && memEQ(name, "html", 4)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
12 |
0 |
12 |
|
| 194 |
12 |
| *t = "text"; *tl = 4; *s = "html"; *sl = 4; return 1; |
| 195 |
|
| } |
| 196 |
|
| /* |
| 197 |
|
| # uncoverable branch true |
| 198 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 199 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 200 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 201 |
8 |
▶ | if (nl == 4 && memEQ(name, "text", 4)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (nl == 4 && memEQ(name, "text", 4)) { |
0 |
8 |
8 |
| if (nl == 4 && memEQ(name, "text", 4)) { |
0 |
0 |
0 |
|
| 202 |
0 |
| *t = "text"; *tl = 4; *s = "plain"; *sl = 5; return 1; /* # uncoverable statement */ |
| 203 |
|
| } |
| 204 |
8 |
▶ | if (nl == 3 && memEQ(name, "xml", 3)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (nl == 3 && memEQ(name, "xml", 3)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
7 |
1 |
8 |
| if (nl == 3 && memEQ(name, "xml", 3)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
7 |
0 |
7 |
|
| 205 |
7 |
| *t = "application"; *tl = 11; *s = "xml"; *sl = 3; return 1; |
| 206 |
|
| } |
| 207 |
1 |
| return 0; |
| 208 |
|
| } |
| 209 |
|
| |
| 210 |
|
| /* Add a token to the response's Vary - creating the pair, or appending to an |
| 211 |
|
| * existing value that does not already carry it (a whole-token check: |
| 212 |
|
| * `Vary: Accept-Encoding` does not contain Accept). Merging rather than |
| 213 |
|
| * replacing is the whole point: an application that already said what it |
| 214 |
|
| * varies on knows something we do not, and a response that varies on |
| 215 |
|
| * something it did not declare poisons every shared cache between here and |
| 216 |
|
| * the client. |
| 217 |
|
| * |
| 218 |
|
| * Used for `Accept` by respond_to and for `Accept-Encoding` by |
| 219 |
|
| * Punk::Plugin::ConditionalGet, which must not grow a second copy of this |
| 220 |
|
| * walk. */ |
| 221 |
111 |
| static void pa_vary_add(pTHX_ AV *headers, const char *tok, STRLEN tl) { |
| 222 |
111 |
| SSize_t i, n = av_len(headers) + 1; |
| 223 |
111 |
| SV *first_vary = NULL; |
| 224 |
336 |
▶ | for (i = 0; i + 1 < n; i += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i + 1 < n; i += 2) { |
232 |
104 |
336 |
|
| 225 |
232 |
| SV **k = av_fetch(headers, i, 0); |
| 226 |
|
| STRLEN kl; const char *kp; |
| 227 |
|
| /* |
| 228 |
|
| # uncoverable branch true class:ignore_covered_err |
| 229 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 230 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 231 |
232 |
▶ | if (!(k && *k)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(k && *k)) continue; |
232 |
0 |
232 |
| if (!(k && *k)) continue; |
0 |
232 |
232 |
|
| 232 |
232 |
| kp = SvPV_const(*k, kl); |
| 233 |
232 |
▶ | if (kl == 4 && foldEQ(kp, "Vary", 4)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (kl == 4 && foldEQ(kp, "Vary", 4)) { |
88 |
144 |
232 |
| if (kl == 4 && foldEQ(kp, "Vary", 4)) { |
13 |
75 |
88 |
|
| 234 |
13 |
| SV **v = av_fetch(headers, i + 1, 0); |
| 235 |
|
| STRLEN vl; const char *vp, *p, *vend; |
| 236 |
|
| /* |
| 237 |
|
| # uncoverable branch true class:ignore_covered_err |
| 238 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 239 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 240 |
|
| # uncoverable condition left count:3 class:ignore_covered_err */ |
| 241 |
13 |
▶ | if (!(v && *v && SvOK(*v))) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(v && *v && SvOK(*v))) continue; |
13 |
0 |
13 |
| if (!(v && *v && SvOK(*v))) continue; |
13 |
0 |
13 |
| if (!(v && *v && SvOK(*v))) continue; |
0 |
13 |
13 |
|
| 242 |
13 |
| vp = SvPV_const(*v, vl); |
| 243 |
13 |
| p = vp; vend = vp + vl; |
| 244 |
19 |
▶ | while (p < vend) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p < vend) { |
13 |
6 |
19 |
|
| 245 |
13 |
| const char *tok_end = p, *t; |
| 246 |
172 |
▶ | while (tok_end < vend && *tok_end != ',') tok_end++; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| while (tok_end < vend && *tok_end != ',') tok_end++; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
159 |
13 |
172 |
| while (tok_end < vend && *tok_end != ',') tok_end++; /* # uncoverable condition right count:2 class:ignore_covered_err */ |
159 |
0 |
159 |
|
| 247 |
13 |
| t = p; |
| 248 |
|
| /* |
| 249 |
|
| # uncoverable branch true class:ignore_covered_err |
| 250 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 251 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 252 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 253 |
13 |
▶ | while (t < tok_end && pa_ws(*t)) t++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (t < tok_end && pa_ws(*t)) t++; |
13 |
0 |
13 |
| while (t < tok_end && pa_ws(*t)) t++; |
0 |
13 |
13 |
|
| 254 |
|
| { |
| 255 |
13 |
| const char *te = tok_end; |
| 256 |
|
| /* |
| 257 |
|
| # uncoverable branch true class:ignore_covered_err |
| 258 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 259 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 260 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 261 |
13 |
▶ | while (te > t && pa_ws(te[-1])) te--; |
Branch: 2 branches
| Branch | True | False | Total |
| while (te > t && pa_ws(te[-1])) te--; |
13 |
0 |
13 |
| while (te > t && pa_ws(te[-1])) te--; |
0 |
13 |
13 |
|
| 262 |
|
| /* `Vary: *` says it varies on everything, so there is |
| 263 |
|
| * nothing to add and nothing a cache may reuse */ |
| 264 |
|
| /* |
| 265 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 266 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 267 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 268 |
13 |
▶ | if ((te - t == 1 && *t == '*') |
Branch: 2 branches
| Branch | True | False | Total |
| if ((te - t == 1 && *t == '*') |
0 |
13 |
13 |
| if ((te - t == 1 && *t == '*') |
0 |
0 |
0 |
|
| 269 |
13 |
▶ | || ((STRLEN)(te - t) == tl && foldEQ(t, tok, tl))) |
Branch: 2 branches
| Branch | True | False | Total |
| || ((STRLEN)(te - t) == tl && foldEQ(t, tok, tl))) |
8 |
5 |
13 |
| || ((STRLEN)(te - t) == tl && foldEQ(t, tok, tl))) |
7 |
1 |
8 |
|
| 270 |
7 |
| return; |
| 271 |
|
| } |
| 272 |
6 |
| p = tok_end + 1; |
| 273 |
|
| } |
| 274 |
|
| /* |
| 275 |
|
| # uncoverable branch false |
| 276 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 277 |
6 |
▶ | if (!first_vary) first_vary = *v; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!first_vary) first_vary = *v; |
6 |
0 |
6 |
|
| 278 |
|
| } |
| 279 |
|
| } |
| 280 |
104 |
▶ | if (first_vary) { sv_catpvs(first_vary, ", "); sv_catpvn(first_vary, tok, tl); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (first_vary) { sv_catpvs(first_vary, ", "); sv_catpvn(first_vary, tok, tl); } |
6 |
98 |
104 |
|
| 281 |
|
| else { |
| 282 |
98 |
| av_push(headers, newSVpvs("Vary")); |
| 283 |
98 |
| av_push(headers, newSVpvn(tok, tl)); |
| 284 |
|
| } |
| 285 |
|
| } |
| 286 |
|
| |
| 287 |
23 |
| static void pa_vary_accept(pTHX_ AV *headers) { |
| 288 |
23 |
| pa_vary_add(aTHX_ headers, "Accept", 6); |
| 289 |
23 |
| } |
| 290 |
|
| |
| 291 |
|
| #endif /* PUNK_ACCEPT_H */ |