| 1 |
|
| /* punk_ua.h - the shared outbound user agent behind $c->ua. |
| 2 |
|
| * |
| 3 |
|
| * One Fetch agent per worker, not one per request. An agent owns a keep-alive |
| 4 |
|
| * connection pool, its DNS state and (when asked for) a cookie jar; building |
| 5 |
|
| * one per request would throw all of that away and pay a fresh TCP and TLS |
| 6 |
|
| * handshake every time, which is the opposite of the reason to reach for |
| 7 |
|
| * Fetch. So $c->ua is a lazy accessor onto the application's agent, and the |
| 8 |
|
| * context slot only memoises that lookup for the request it belongs to. |
| 9 |
|
| * |
| 10 |
|
| * The pid is stored beside the agent and checked on every fetch, exactly as |
| 11 |
|
| * punk_dbi.h does for a database handle: an agent built before a fork would |
| 12 |
|
| * otherwise have every worker sharing one set of sockets. A worker that finds |
| 13 |
|
| * a foreign pid builds its own. |
| 14 |
|
| * |
| 15 |
|
| * The agent binds to the worker's Hyperman loop when there is one, so an |
| 16 |
|
| * outbound call rides the same loop serving inbound requests and the worker |
| 17 |
|
| * keeps answering while it is in flight. Outside a worker - a test, a script, |
| 18 |
|
| * punk console - Hyperman->loop is undef, Fetch falls back to its own |
| 19 |
|
| * standalone loop and ->get blocks. That is the same degradation $c->timer |
| 20 |
|
| * already documents. |
| 21 |
|
| * |
| 22 |
|
| * Perl headers and punk_context.h (pcx_call_meth) must be in scope. |
| 23 |
|
| */ |
| 24 |
|
| |
| 25 |
|
| #ifndef PUNK_UA_H |
| 26 |
|
| #define PUNK_UA_H |
| 27 |
|
| |
| 28 |
|
| /* The config the `ua` keyword froze for one agent, or NULL when that name was |
| 29 |
|
| * never declared. An undeclared default is not an error - an app that never |
| 30 |
|
| * says `ua` still gets a default agent - but an undeclared NAME is, and |
| 31 |
|
| * pua_shared turns this into that croak. */ |
| 32 |
45 |
| static HV *pua_cfg(pTHX_ SV *app, const char *name, STRLEN nlen) { |
| 33 |
|
| SV **s, **e; |
| 34 |
|
| HV *uas; |
| 35 |
|
| /* |
| 36 |
|
| # uncoverable branch true |
| 37 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 38 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 39 |
|
| # uncoverable condition left count:3 class:ignore_covered_err */ |
| 40 |
45 |
▶ | if (!(app && SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV)) return NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(app && SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV)) return NULL; |
45 |
0 |
45 |
| if (!(app && SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV)) return NULL; |
45 |
0 |
45 |
| if (!(app && SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV)) return NULL; |
0 |
45 |
45 |
|
| 41 |
45 |
| s = hv_fetchs((HV *)SvRV(app), K_UA, 0); |
| 42 |
|
| /* |
| 43 |
|
| # uncoverable branch true |
| 44 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 45 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 46 |
|
| # uncoverable condition left count:3 class:ignore_covered_err |
| 47 |
|
| # uncoverable condition left count:4 class:ignore_covered_err */ |
| 48 |
45 |
▶ | if (!(s && *s && SvROK(*s) && SvTYPE(SvRV(*s)) == SVt_PVHV)) return NULL; |
Branch: 4 branches
| Branch | True | False | Total |
| if (!(s && *s && SvROK(*s) && SvTYPE(SvRV(*s)) == SVt_PVHV)) return NULL; |
45 |
0 |
45 |
| if (!(s && *s && SvROK(*s) && SvTYPE(SvRV(*s)) == SVt_PVHV)) return NULL; |
45 |
0 |
45 |
| if (!(s && *s && SvROK(*s) && SvTYPE(SvRV(*s)) == SVt_PVHV)) return NULL; |
45 |
0 |
45 |
| if (!(s && *s && SvROK(*s) && SvTYPE(SvRV(*s)) == SVt_PVHV)) return NULL; |
0 |
45 |
45 |
|
| 49 |
45 |
| uas = (HV *)SvRV(*s); |
| 50 |
45 |
| e = hv_fetch(uas, name, (I32)nlen, 0); |
| 51 |
44 |
▶ | return (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV) |
Branch: 3 branches
| Branch | True | False | Total |
| return (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV) |
44 |
0 |
44 |
| return (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV) |
44 |
0 |
44 |
| return (e && *e && SvROK(*e) && SvTYPE(SvRV(*e)) == SVt_PVHV) |
44 |
0 |
44 |
|
| 52 |
89 |
▶ | ? (HV *)SvRV(*e) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? (HV *)SvRV(*e) : NULL; |
44 |
1 |
45 |
|
| 53 |
|
| } |
| 54 |
|
| |
| 55 |
|
| /* Is this key one of Fetch's own constructor options? |
| 56 |
|
| * |
| 57 |
|
| * Needed to read a punk.yml `ua:` block, where a nested mapping is how a |
| 58 |
|
| * second agent is named - except that `headers` is an option whose value is |
| 59 |
|
| * itself a mapping. Deciding on the key rather than the value shape keeps |
| 60 |
|
| * `headers: {...}` an option and anything else nested a name. */ |
| 61 |
2 |
| static int pua_is_known_opt(pTHX_ const char *k, STRLEN kl) { |
| 62 |
|
| static const char *opts[] = { |
| 63 |
|
| "headers", "agent", "timeout", "tls_verify", "max_redirects", |
| 64 |
|
| "keep_alive", "pool_size", "cookie_jar", "simple_response", NULL |
| 65 |
|
| }; |
| 66 |
|
| int i; |
| 67 |
|
| PERL_UNUSED_CONTEXT; |
| 68 |
20 |
▶ | for (i = 0; opts[i]; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; opts[i]; i++) |
18 |
2 |
20 |
|
| 69 |
|
| /* |
| 70 |
|
| # uncoverable branch true class:ignore_covered_err |
| 71 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 72 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 73 |
18 |
▶ | if (strlen(opts[i]) == kl && memEQ(k, opts[i], kl)) return 1; |
Branch: 2 branches
| Branch | True | False | Total |
| if (strlen(opts[i]) == kl && memEQ(k, opts[i], kl)) return 1; |
4 |
14 |
18 |
| if (strlen(opts[i]) == kl && memEQ(k, opts[i], kl)) return 1; |
0 |
4 |
4 |
|
| 74 |
2 |
| return 0; |
| 75 |
|
| } |
| 76 |
|
| |
| 77 |
|
| /* What cookie_jar was asked for. A jar belongs to the agent, so a jar on the |
| 78 |
|
| * worker-shared agent is shared by every request that worker serves - which is |
| 79 |
|
| * a cross-request leak the moment the cookies identify an end user rather than |
| 80 |
|
| * the application itself. So the setting decides which agent a request gets: |
| 81 |
|
| * |
| 82 |
|
| * PUA_JAR_NONE no jar (default): the shared agent, as-is. |
| 83 |
|
| * PUA_JAR_REQUEST cookie_jar => 1: Fetch->clone(cookie_jar => 1) per |
| 84 |
|
| * request. Its own jar, so cookies cannot outlive the |
| 85 |
|
| * request that collected them, over the shared connection |
| 86 |
|
| * pool and loop - a clone exists precisely so this costs |
| 87 |
|
| * neither. |
| 88 |
|
| * PUA_JAR_SHARED cookie_jar => 'shared': one jar on the shared agent, for |
| 89 |
|
| * an upstream that authenticates THIS APPLICATION and where |
| 90 |
|
| * a persistent session cookie is the point. Spelled out in |
| 91 |
|
| * full so nobody arrives here by accident. |
| 92 |
|
| */ |
| 93 |
|
| #define PUA_JAR_NONE 0 |
| 94 |
|
| #define PUA_JAR_REQUEST 1 |
| 95 |
|
| #define PUA_JAR_SHARED 2 |
| 96 |
|
| |
| 97 |
39 |
| static int pua_jar_mode(pTHX_ HV *cfg) { |
| 98 |
39 |
▶ | SV **j = cfg ? hv_fetchs(cfg, "cookie_jar", 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
Branch: 1 branch
| Branch | True | False | Total |
| SV **j = cfg ? hv_fetchs(cfg, "cookie_jar", 0) : NULL; /* # uncoverable condition right count:1 class:ignore_covered_err */ |
39 |
0 |
39 |
|
| 99 |
|
| /* |
| 100 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 101 |
|
| # uncoverable condition left count:3 class:ignore_covered_err |
| 102 |
|
| # uncoverable condition left count:4 class:ignore_covered_err */ |
| 103 |
39 |
▶ | if (!(j && *j && SvOK(*j) && SvTRUE(*j))) return PUA_JAR_NONE; |
Branch: 4 branches
| Branch | True | False | Total |
| if (!(j && *j && SvOK(*j) && SvTRUE(*j))) return PUA_JAR_NONE; |
11 |
28 |
39 |
| if (!(j && *j && SvOK(*j) && SvTRUE(*j))) return PUA_JAR_NONE; |
11 |
0 |
11 |
| if (!(j && *j && SvOK(*j) && SvTRUE(*j))) return PUA_JAR_NONE; |
11 |
0 |
11 |
| if (!(j && *j && SvOK(*j) && SvTRUE(*j))) return PUA_JAR_NONE; |
0 |
11 |
11 |
|
| 104 |
11 |
▶ | if (SvPOK(*j)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvPOK(*j)) { |
3 |
8 |
11 |
|
| 105 |
3 |
| STRLEN l; const char *p = SvPV_const(*j, l); |
| 106 |
|
| /* |
| 107 |
|
| # uncoverable branch false |
| 108 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 109 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 110 |
3 |
▶ | if (l == 6 && memEQ(p, "shared", 6)) return PUA_JAR_SHARED; |
Branch: 2 branches
| Branch | True | False | Total |
| if (l == 6 && memEQ(p, "shared", 6)) return PUA_JAR_SHARED; |
3 |
0 |
3 |
| if (l == 6 && memEQ(p, "shared", 6)) return PUA_JAR_SHARED; |
3 |
0 |
3 |
|
| 111 |
|
| } |
| 112 |
8 |
| return PUA_JAR_REQUEST; |
| 113 |
|
| } |
| 114 |
|
| |
| 115 |
|
| /* The worker's Hyperman::Loop, or NULL outside a worker. |
| 116 |
|
| * |
| 117 |
|
| * Deliberately does not load Hyperman. It is a prerequisite, so it is |
| 118 |
|
| * installed, but that is not the same as loaded - and if it has not been |
| 119 |
|
| * loaded in this process then by definition no worker loop is running here, so |
| 120 |
|
| * there is nothing to bind to and requiring it would only cost a script or a |
| 121 |
|
| * test the load. An unloaded Hyperman and a loaded one sitting outside a |
| 122 |
|
| * worker are the same answer: no loop. */ |
| 123 |
10 |
| static SV *pua_loop(pTHX) { |
| 124 |
|
| SV *l; |
| 125 |
|
| /* |
| 126 |
|
| # uncoverable branch true |
| 127 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 128 |
10 |
▶ | if (!gv_stashpvs("Hyperman", 0)) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!gv_stashpvs("Hyperman", 0)) return NULL; |
0 |
10 |
10 |
|
| 129 |
10 |
| l = pcx_call_meth(aTHX_ sv_2mortal(newSVpvs("Hyperman")), "loop", |
| 130 |
|
| NULL, 0, 1); |
| 131 |
|
| /* |
| 132 |
|
| # uncoverable branch true |
| 133 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 134 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 135 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 136 |
10 |
▶ | if (l && SvOK(l)) return l; |
Branch: 2 branches
| Branch | True | False | Total |
| if (l && SvOK(l)) return l; |
10 |
0 |
10 |
| if (l && SvOK(l)) return l; |
0 |
10 |
10 |
|
| 137 |
|
| /* |
| 138 |
|
| # uncoverable branch false |
| 139 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 140 |
10 |
▶ | if (l) SvREFCNT_dec(l); |
Branch: 1 branch
| Branch | True | False | Total |
| if (l) SvREFCNT_dec(l); |
10 |
0 |
10 |
|
| 141 |
10 |
| return NULL; |
| 142 |
|
| } |
| 143 |
|
| |
| 144 |
|
| /* Fetch->new(%cfg, loop => $loop). Returns a +1 agent, or croaks the way any |
| 145 |
|
| * other boot-time misconfiguration does. */ |
| 146 |
10 |
| static SV *pua_build(pTHX_ SV *app, const char *name, STRLEN nlen) { |
| 147 |
|
| HV *cfg; |
| 148 |
|
| SV *loop; |
| 149 |
|
| SV **argv; |
| 150 |
|
| SV *agent; |
| 151 |
10 |
| int n = 0, cap; |
| 152 |
|
| HE *e; |
| 153 |
|
| |
| 154 |
|
| /* Loaded on first use rather than at boot: an application that never |
| 155 |
|
| * reaches for $c->ua should not pay for the agent's dependencies. */ |
| 156 |
|
| /* |
| 157 |
|
| # uncoverable branch true |
| 158 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 159 |
10 |
▶ | if (!gv_stashpvs("Fetch", 0)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!gv_stashpvs("Fetch", 0)) { |
0 |
10 |
10 |
|
| 160 |
|
| /* |
| 161 |
|
| # uncoverable statement |
| 162 |
|
| # uncoverable branch true |
| 163 |
|
| # uncoverable branch false |
| 164 |
|
| # uncoverable condition left count:1 |
| 165 |
|
| # uncoverable condition right count:1 */ |
| 166 |
0 |
▶ | if (!pk_require_once(aTHX_ "Fetch", FALSE)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pk_require_once(aTHX_ "Fetch", FALSE)) |
0 |
0 |
0 |
|
| 167 |
0 |
▶ | croak("Punk: $c->ua needs Fetch: %s", SvPV_nolen(ERRSV)); /* # uncoverable statement */ |
Branch: 1 branch
| Branch | True | False | Total |
| croak("Punk: $c->ua needs Fetch: %s", SvPV_nolen(ERRSV)); /* # uncoverable statement */ |
0 |
0 |
0 |
|
| 168 |
|
| } |
| 169 |
|
| |
| 170 |
10 |
| cfg = pua_cfg(aTHX_ app, name, nlen); |
| 171 |
10 |
| loop = pua_loop(aTHX); |
| 172 |
|
| |
| 173 |
|
| /* |
| 174 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 175 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 176 |
10 |
▶ | cap = (cfg ? (int)HvUSEDKEYS(cfg) * 2 : 0) + 4; |
Branch: 2 branches
| Branch | True | False | Total |
| cap = (cfg ? (int)HvUSEDKEYS(cfg) * 2 : 0) + 4; |
10 |
0 |
10 |
| cap = (cfg ? (int)HvUSEDKEYS(cfg) * 2 : 0) + 4; |
0 |
10 |
10 |
|
| 177 |
10 |
| Newx(argv, cap, SV *); |
| 178 |
|
| /* |
| 179 |
|
| # uncoverable branch false |
| 180 |
|
| # uncoverable condition right count:1 class:ignore_covered_err */ |
| 181 |
10 |
▶ | if (cfg) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cfg) { |
10 |
0 |
10 |
|
| 182 |
10 |
| int mode = pua_jar_mode(aTHX_ cfg); |
| 183 |
10 |
| hv_iterinit(cfg); |
| 184 |
25 |
▶ | while ((e = hv_iternext(cfg))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((e = hv_iternext(cfg))) { |
15 |
10 |
25 |
|
| 185 |
|
| STRLEN kl; |
| 186 |
15 |
▶ | const char *k = HePV(e, kl); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *k = HePV(e, kl); |
0 |
15 |
15 |
|
| 187 |
|
| /* cookie_jar never reaches the shared agent verbatim: in |
| 188 |
|
| * per-request mode the jar belongs to the clone, and 'shared' is |
| 189 |
|
| * Punk's spelling, not one Fetch knows. */ |
| 190 |
15 |
▶ | if (kl == 10 && memEQ(k, "cookie_jar", 10)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (kl == 10 && memEQ(k, "cookie_jar", 10)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
3 |
12 |
15 |
| if (kl == 10 && memEQ(k, "cookie_jar", 10)) { /* # uncoverable condition right count:2 class:ignore_covered_err */ |
3 |
0 |
3 |
|
| 191 |
3 |
▶ | if (mode == PUA_JAR_SHARED) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (mode == PUA_JAR_SHARED) { |
1 |
2 |
3 |
|
| 192 |
1 |
| argv[n++] = sv_2mortal(newSVpvs("cookie_jar")); |
| 193 |
1 |
| argv[n++] = sv_2mortal(newSViv(1)); |
| 194 |
|
| } |
| 195 |
3 |
| continue; |
| 196 |
|
| } |
| 197 |
12 |
| argv[n++] = sv_2mortal(newSVpvn(k, kl)); |
| 198 |
12 |
| argv[n++] = sv_2mortal(newSVsv(hv_iterval(cfg, e))); |
| 199 |
|
| } |
| 200 |
|
| } |
| 201 |
|
| /* |
| 202 |
|
| # uncoverable branch true |
| 203 |
|
| # uncoverable condition left count:1 class:ignore_covered_err */ |
| 204 |
10 |
▶ | if (loop) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (loop) { |
0 |
10 |
10 |
|
| 205 |
0 |
| argv[n++] = sv_2mortal(newSVpvs("loop")); /* # uncoverable statement */ |
| 206 |
0 |
| argv[n++] = sv_2mortal(loop); /* pua_loop handed us +1 */ /* # uncoverable statement */ |
| 207 |
|
| } |
| 208 |
10 |
| agent = pcx_call_meth(aTHX_ sv_2mortal(newSVpvs("Fetch")), "new", |
| 209 |
|
| argv, n, 1); |
| 210 |
10 |
| Safefree(argv); |
| 211 |
|
| /* |
| 212 |
|
| # uncoverable branch true |
| 213 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 214 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 215 |
10 |
▶ | if (!(agent && SvROK(agent))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(agent && SvROK(agent))) |
10 |
0 |
10 |
| if (!(agent && SvROK(agent))) |
0 |
10 |
10 |
|
| 216 |
0 |
| croak("Punk: $c->ua could not build a Fetch agent"); /* # uncoverable statement */ |
| 217 |
10 |
| return agent; |
| 218 |
|
| } |
| 219 |
|
| |
| 220 |
|
| /* This worker's shared agent for one name, built on first use in it. Borrowed |
| 221 |
|
| * - the app holds the reference. Each name gets its own agent, so two |
| 222 |
|
| * upstreams do not share a pool, a timeout or a set of default headers. */ |
| 223 |
30 |
| static SV *pua_shared(pTHX_ SV *app, const char *name, STRLEN nlen) { |
| 224 |
|
| HV *h, *cache, *box; |
| 225 |
|
| SV **slot, **pid, **a; |
| 226 |
|
| |
| 227 |
|
| /* |
| 228 |
|
| # uncoverable branch true |
| 229 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 230 |
|
| # uncoverable condition left count:2 class:ignore_covered_err |
| 231 |
|
| # uncoverable condition left count:3 class:ignore_covered_err */ |
| 232 |
30 |
▶ | if (!(app && SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV)) |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(app && SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV)) |
30 |
0 |
30 |
| if (!(app && SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV)) |
30 |
0 |
30 |
| if (!(app && SvROK(app) && SvTYPE(SvRV(app)) == SVt_PVHV)) |
0 |
30 |
30 |
|
| 233 |
0 |
| croak("Punk: $c->ua needs the compiled application"); /* # uncoverable statement */ |
| 234 |
30 |
| h = (HV *)SvRV(app); |
| 235 |
|
| |
| 236 |
|
| /* A name that was never declared is a mistake worth naming, unlike the |
| 237 |
|
| * default, which an application is entitled never to configure. */ |
| 238 |
30 |
▶ | if (!(nlen == sizeof(K_DEFAULT) - 1 && memEQ(name, K_DEFAULT, nlen)) /* # uncoverable condition left count:2 class:ignore_covered_err */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(nlen == sizeof(K_DEFAULT) - 1 && memEQ(name, K_DEFAULT, nlen)) /* # uncoverable condition left count:2 class:ignore_covered_err */ |
29 |
1 |
30 |
| if (!(nlen == sizeof(K_DEFAULT) - 1 && memEQ(name, K_DEFAULT, nlen)) /* # uncoverable condition left count:2 class:ignore_covered_err */ |
5 |
24 |
29 |
|
| 239 |
6 |
▶ | && !pua_cfg(aTHX_ app, name, nlen)) |
Branch: 1 branch
| Branch | True | False | Total |
| && !pua_cfg(aTHX_ app, name, nlen)) |
1 |
5 |
6 |
|
| 240 |
1 |
| croak("Punk: $c->ua('%.*s') is not a configured agent; declare it " |
| 241 |
|
| "with `ua %.*s => { ... }`", (int)nlen, name, (int)nlen, name); |
| 242 |
|
| |
| 243 |
29 |
| slot = hv_fetchs(h, K_UA_AGENT, 0); |
| 244 |
|
| /* |
| 245 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 246 |
|
| # uncoverable condition right count:3 class:ignore_covered_err |
| 247 |
|
| # uncoverable condition right count:4 class:ignore_covered_err */ |
| 248 |
29 |
▶ | if (slot && *slot && SvROK(*slot) && SvTYPE(SvRV(*slot)) == SVt_PVHV) |
Branch: 4 branches
| Branch | True | False | Total |
| if (slot && *slot && SvROK(*slot) && SvTYPE(SvRV(*slot)) == SVt_PVHV) |
22 |
7 |
29 |
| if (slot && *slot && SvROK(*slot) && SvTYPE(SvRV(*slot)) == SVt_PVHV) |
22 |
0 |
22 |
| if (slot && *slot && SvROK(*slot) && SvTYPE(SvRV(*slot)) == SVt_PVHV) |
22 |
0 |
22 |
| if (slot && *slot && SvROK(*slot) && SvTYPE(SvRV(*slot)) == SVt_PVHV) |
22 |
0 |
22 |
|
| 249 |
22 |
| cache = (HV *)SvRV(*slot); |
| 250 |
|
| else { |
| 251 |
7 |
| cache = newHV(); |
| 252 |
7 |
| (void)hv_stores(h, K_UA_AGENT, newRV_noinc((SV *)cache)); |
| 253 |
|
| } |
| 254 |
|
| |
| 255 |
29 |
| slot = hv_fetch(cache, name, (I32)nlen, 0); |
| 256 |
|
| /* |
| 257 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 258 |
|
| # uncoverable condition right count:3 class:ignore_covered_err |
| 259 |
|
| # uncoverable condition right count:4 class:ignore_covered_err */ |
| 260 |
29 |
▶ | if (slot && *slot && SvROK(*slot) && SvTYPE(SvRV(*slot)) == SVt_PVHV) { |
Branch: 4 branches
| Branch | True | False | Total |
| if (slot && *slot && SvROK(*slot) && SvTYPE(SvRV(*slot)) == SVt_PVHV) { |
20 |
9 |
29 |
| if (slot && *slot && SvROK(*slot) && SvTYPE(SvRV(*slot)) == SVt_PVHV) { |
20 |
0 |
20 |
| if (slot && *slot && SvROK(*slot) && SvTYPE(SvRV(*slot)) == SVt_PVHV) { |
20 |
0 |
20 |
| if (slot && *slot && SvROK(*slot) && SvTYPE(SvRV(*slot)) == SVt_PVHV) { |
20 |
0 |
20 |
|
| 261 |
20 |
| box = (HV *)SvRV(*slot); |
| 262 |
20 |
| pid = hv_fetchs(box, "pid", 0); |
| 263 |
|
| /* |
| 264 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 265 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 266 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 267 |
20 |
▶ | if (pid && *pid && SvOK(*pid) |
Branch: 3 branches
| Branch | True | False | Total |
| if (pid && *pid && SvOK(*pid) |
20 |
0 |
20 |
| if (pid && *pid && SvOK(*pid) |
20 |
0 |
20 |
| if (pid && *pid && SvOK(*pid) |
20 |
0 |
20 |
|
| 268 |
20 |
▶ | && SvIV(*pid) == (IV)PerlProc_getpid()) { |
Branch: 1 branch
| Branch | True | False | Total |
| && SvIV(*pid) == (IV)PerlProc_getpid()) { |
19 |
1 |
20 |
|
| 269 |
19 |
| a = hv_fetchs(box, "agent", 0); |
| 270 |
|
| /* |
| 271 |
|
| # uncoverable branch false |
| 272 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 273 |
|
| # uncoverable condition right count:2 class:ignore_covered_err |
| 274 |
|
| # uncoverable condition right count:3 class:ignore_covered_err */ |
| 275 |
19 |
▶ | if (a && *a && SvROK(*a)) return *a; |
Branch: 3 branches
| Branch | True | False | Total |
| if (a && *a && SvROK(*a)) return *a; |
19 |
0 |
19 |
| if (a && *a && SvROK(*a)) return *a; |
19 |
0 |
19 |
| if (a && *a && SvROK(*a)) return *a; |
19 |
0 |
19 |
|
| 276 |
|
| } |
| 277 |
|
| /* a foreign pid: this worker was forked from whoever built that one, |
| 278 |
|
| * so drop it rather than share its sockets */ |
| 279 |
|
| } |
| 280 |
|
| |
| 281 |
10 |
| box = newHV(); |
| 282 |
10 |
| (void)hv_stores(box, "agent", pua_build(aTHX_ app, name, nlen)); |
| 283 |
10 |
| (void)hv_stores(box, "pid", newSViv((IV)PerlProc_getpid())); |
| 284 |
10 |
| (void)hv_store(cache, name, (I32)nlen, newRV_noinc((SV *)box), 0); |
| 285 |
10 |
| a = hv_fetchs(box, "agent", 0); |
| 286 |
|
| /* |
| 287 |
|
| # uncoverable condition right count:1 class:ignore_covered_err |
| 288 |
|
| # uncoverable condition right count:2 class:ignore_covered_err */ |
| 289 |
10 |
▶ | return (a && *a) ? *a : &PL_sv_undef; |
Branch: 2 branches
| Branch | True | False | Total |
| return (a && *a) ? *a : &PL_sv_undef; |
10 |
0 |
10 |
| return (a && *a) ? *a : &PL_sv_undef; |
10 |
0 |
10 |
|
| 290 |
|
| } |
| 291 |
|
| |
| 292 |
|
| /* The agent this request should use, +1 to the caller. |
| 293 |
|
| * |
| 294 |
|
| * With a per-request jar that is a clone of the shared one: its own jar, over |
| 295 |
|
| * the shared connection pool and loop, so isolation costs neither. Otherwise |
| 296 |
|
| * it is the shared agent itself. Either way the context memoises it, so a |
| 297 |
|
| * handler calling $c->ua twice gets one agent and one jar. */ |
| 298 |
30 |
| static SV *pua_agent(pTHX_ SV *app, const char *name, STRLEN nlen) { |
| 299 |
30 |
| SV *shared = pua_shared(aTHX_ app, name, nlen); |
| 300 |
|
| SV *clone; |
| 301 |
|
| SV *argv[2]; |
| 302 |
|
| |
| 303 |
29 |
▶ | if (pua_jar_mode(aTHX_ pua_cfg(aTHX_ app, name, nlen)) != PUA_JAR_REQUEST) |
Branch: 1 branch
| Branch | True | False | Total |
| if (pua_jar_mode(aTHX_ pua_cfg(aTHX_ app, name, nlen)) != PUA_JAR_REQUEST) |
23 |
6 |
29 |
|
| 304 |
23 |
| return SvREFCNT_inc(shared); |
| 305 |
|
| |
| 306 |
6 |
| argv[0] = sv_2mortal(newSVpvs("cookie_jar")); |
| 307 |
6 |
| argv[1] = sv_2mortal(newSViv(1)); |
| 308 |
6 |
| clone = pcx_call_meth(aTHX_ shared, "clone", argv, 2, 1); |
| 309 |
|
| /* |
| 310 |
|
| # uncoverable branch true |
| 311 |
|
| # uncoverable condition left count:1 class:ignore_covered_err |
| 312 |
|
| # uncoverable condition left count:2 class:ignore_covered_err */ |
| 313 |
6 |
▶ | if (!(clone && SvROK(clone))) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(clone && SvROK(clone))) |
6 |
0 |
6 |
| if (!(clone && SvROK(clone))) |
0 |
6 |
6 |
|
| 314 |
0 |
| croak("Punk: $c->ua could not clone the agent for this request " /* # uncoverable statement */ |
| 315 |
|
| "(Fetch 0.11 or later is needed for a per-request cookie jar)"); |
| 316 |
6 |
| return clone; |
| 317 |
|
| } |
| 318 |
|
| |
| 319 |
|
| #endif /* PUNK_UA_H */ |