Branch Coverage

feersum_psgi.c.inc
Criterion Covered Total %
branch 400 676 59.1


line true false branch
8 15 3 if (!val || val_len == 0) return NULL;
0 15 if (!val || val_len == 0) return NULL;
11 15 0 while (val_len > 0 && (*val == ' ' || *val == '\t')) { val++; val_len--; }
0 15 while (val_len > 0 && (*val == ' ' || *val == '\t')) { val++; val_len--; }
0 15 while (val_len > 0 && (*val == ' ' || *val == '\t')) { val++; val_len--; }
12 0 15 if (val_len == 0) return NULL;
16 178 9 while (ip_len < val_len && val[ip_len] != ',' && val[ip_len] != ' ') ip_len++;
173 5 while (ip_len < val_len && val[ip_len] != ',' && val[ip_len] != ' ') ip_len++;
172 1 while (ip_len < val_len && val[ip_len] != ',' && val[ip_len] != ' ') ip_len++;
18 15 0 if (ip_len == 0 || ip_len > 45) return NULL; // max IPv6 length is 45 chars
0 15 if (ip_len == 0 || ip_len > 45) return NULL; // max IPv6 length is 45 chars
28 9 6 if (inet_pton(AF_INET, ip_buf, &addr4) == 1) {
31 2 4 if (inet_pton(AF_INET6, ip_buf, &addr6) == 1) {
45 7 10 if (!val || val_len == 0) return NULL;
0 7 if (!val || val_len == 0) return NULL;
48 7 0 while (val_len > 0 && (*val == ' ' || *val == '\t')) { val++; val_len--; }
0 7 while (val_len > 0 && (*val == ' ' || *val == '\t')) { val++; val_len--; }
0 7 while (val_len > 0 && (*val == ' ' || *val == '\t')) { val++; val_len--; }
51 7 0 if (val_len >= 5 && str_case_eq_fixed("https", val, 5) &&
7 0 if (val_len >= 5 && str_case_eq_fixed("https", val, 5) &&
52 1 6 (val_len == 5 || val[5] == ' ' || val[5] == '\t' || val[5] == ','))
1 0 (val_len == 5 || val[5] == ' ' || val[5] == '\t' || val[5] == ','))
1 0 (val_len == 5 || val[5] == ' ' || val[5] == '\t' || val[5] == ','))
1 0 (val_len == 5 || val[5] == ' ' || val[5] == '\t' || val[5] == ','))
54 0 0 if (val_len >= 4 && str_case_eq_fixed("http", val, 4) &&
0 0 if (val_len >= 4 && str_case_eq_fixed("http", val, 4) &&
55 0 0 (val_len == 4 || val[4] == ' ' || val[4] == '\t' || val[4] == ','))
0 0 (val_len == 4 || val[4] == ' ' || val[4] == '\t' || val[4] == ','))
0 0 (val_len == 4 || val[4] == ' ' || val[4] == '\t' || val[4] == ','))
0 0 (val_len == 4 || val[4] == ' ' || val[4] == '\t' || val[4] == ','))
72 39 264 if (c->tls) return newSVpvs("https");
74 2 262 if (c->proxy_ssl) return newSVpvs("https");
75 23 239 if (c->proxy_proto_version > 0 && c->proxy_dst_port == 443)
5 18 if (c->proxy_proto_version > 0 && c->proxy_dst_port == 443)
77 17 240 if (c->cached_use_reverse_proxy && c->req) {
17 0 if (c->cached_use_reverse_proxy && c->req) {
79 7 10 if (fwd) return fwd;
88 0 56 if (psgi_env_version) return; // already initialized
130 56 236 if (unlikely(!psgi_env_version))
143 292 0 hv_stores(e, "SERVER_NAME",
145 292 0 hv_stores(e, "SERVER_PORT",
162 13 279 if (c->cached_use_reverse_proxy) {
164 5 8 hv_stores(e, "REMOTE_ADDR", fwd_addr ? fwd_addr : SvREFCNT_inc_simple_NN(c->remote_addr));
172 244 48 hv_stores(e, "psgi.url_scheme", scheme ? scheme : newSVpvs("http"));
181 0 292 hv_stores(e, "psgi.multiprocess",
0 292 hv_stores(e, "psgi.multiprocess",
184 88 204 if (c->cached_request_cb_is_psgi && c->server->psgix_io) {
88 0 if (c->cached_request_cb_is_psgi && c->server->psgix_io) {
191 0 292 if (c->trailers) {
195 1 291 if (c->proxy_tlvs) {
199 291 1 if (likely(!r->path)) feersum_set_path_and_query(aTHX_ r);
206 838 292 for (i=0; inum_headers; i++) {
225 0 785 if (unlikely(hdr->name_len > MAX_HEADER_NAME_LEN)) {
233 6644 785 for (j=0; jname_len; j++) {
243 0 785 if (unlikely(fetched == NULL)) {
248 2 783 if (unlikely(SvPOK(cur_val))) {
251 0 2 const char *sep = (hdr->name_len == 6
252 0 0 && str_case_eq_fixed("cookie", hdr->name, 6)) ? "; " : ", ";
317 7 0 if (r->num_headers > 0)
322 0 3 COPY_NORM_HEADER(n)
22 3 COPY_NORM_HEADER(n)
0 3 COPY_NORM_HEADER(n)
0 3 COPY_NORM_HEADER(n)
0 0 COPY_NORM_HEADER(n)
0 0 COPY_NORM_HEADER(n)
3 1 COPY_NORM_HEADER(n)
324 0 9 COPY_NORM_HEADER(ascii_lower[(unsigned char)n])
60 9 COPY_NORM_HEADER(ascii_lower[(unsigned char)n])
0 9 COPY_NORM_HEADER(ascii_lower[(unsigned char)n])
2 7 COPY_NORM_HEADER(ascii_lower[(unsigned char)n])
2 0 COPY_NORM_HEADER(ascii_lower[(unsigned char)n])
1 1 COPY_NORM_HEADER(ascii_lower[(unsigned char)n])
9 2 COPY_NORM_HEADER(ascii_lower[(unsigned char)n])
326 0 3 COPY_NORM_HEADER(ascii_upper[(unsigned char)n])
22 3 COPY_NORM_HEADER(ascii_upper[(unsigned char)n])
0 3 COPY_NORM_HEADER(ascii_upper[(unsigned char)n])
0 3 COPY_NORM_HEADER(ascii_upper[(unsigned char)n])
0 0 COPY_NORM_HEADER(ascii_upper[(unsigned char)n])
0 0 COPY_NORM_HEADER(ascii_upper[(unsigned char)n])
3 1 COPY_NORM_HEADER(ascii_upper[(unsigned char)n])
328 0 8 COPY_NORM_HEADER(ascii_lower_dash[(unsigned char)n])
72 8 COPY_NORM_HEADER(ascii_lower_dash[(unsigned char)n])
0 8 COPY_NORM_HEADER(ascii_lower_dash[(unsigned char)n])
0 8 COPY_NORM_HEADER(ascii_lower_dash[(unsigned char)n])
0 0 COPY_NORM_HEADER(ascii_lower_dash[(unsigned char)n])
0 0 COPY_NORM_HEADER(ascii_lower_dash[(unsigned char)n])
8 2 COPY_NORM_HEADER(ascii_lower_dash[(unsigned char)n])
330 0 3 COPY_NORM_HEADER(ascii_upper_dash[(unsigned char)n])
22 3 COPY_NORM_HEADER(ascii_upper_dash[(unsigned char)n])
0 3 COPY_NORM_HEADER(ascii_upper_dash[(unsigned char)n])
0 3 COPY_NORM_HEADER(ascii_upper_dash[(unsigned char)n])
0 0 COPY_NORM_HEADER(ascii_upper_dash[(unsigned char)n])
0 0 COPY_NORM_HEADER(ascii_upper_dash[(unsigned char)n])
3 1 COPY_NORM_HEADER(ascii_upper_dash[(unsigned char)n])
345 2 8 const bool is_cookie = (nlen == 6 && str_case_eq_fixed("cookie", np, 6));
1 1 const bool is_cookie = (nlen == 6 && str_case_eq_fixed("cookie", np, 6));
346 42 10 for (i = 0; i < r->num_headers; i++) {
348 16 26 if (unlikely(hdr->name_len == nlen
12 4 if (unlikely(hdr->name_len == nlen
350 10 2 if (likely(!result)) {
353 1 1 sv_catpvn(result, is_cookie ? "; " : ", ", 2);
358 10 0 return result ? result : &PL_sv_undef;
373 1 12 if (unlikely(c->io_taken))
375 0 12 if (unlikely(c->responding != RESPOND_NOT_STARTED))
438 9 3 if (c->tls) {
440 0 9 if (!c->tls_tunnel)
447 0 9 PUSHMARK(SP);
448 0 9 XPUSHs(sv);
449 0 9 mXPUSHs(newSViv(c->tls_tunnel_sv1));
455 9 0 if (unlikely(SvTRUE(ERRSV))) {
0 9 if (unlikely(SvTRUE(ERRSV))) {
456 0 0 FREETMPS;
459 0 0 croak("Failed to create TLS tunnel IO handle: %-p", ERRSV);
462 0 9 if (unlikely(!SvROK(sv))) {
465 0 0 FREETMPS;
482 9 0 FREETMPS;
494 0 3 PUSHMARK(SP);
495 0 3 XPUSHs(sv);
496 0 3 mXPUSHs(newSViv(c->fd));
503 3 0 if (unlikely(SvTRUE(ERRSV))) {
0 3 if (unlikely(SvTRUE(ERRSV))) {
504 0 0 FREETMPS;
507 0 0 croak("Failed to create IO handle: %-p", ERRSV);
511 0 3 if (unlikely(!SvROK(sv))) {
512 0 0 FREETMPS;
523 3 0 if (likely(c->rbuf && SvOK(c->rbuf) && SvCUR(c->rbuf))) {
3 0 if (likely(c->rbuf && SvOK(c->rbuf) && SvCUR(c->rbuf))) {
3 0 if (likely(c->rbuf && SvOK(c->rbuf) && SvCUR(c->rbuf))) {
1 2 if (likely(c->rbuf && SvOK(c->rbuf) && SvCUR(c->rbuf))) {
527 1 0 if (io) {
529 1 0 if (likely(pushed == (SSize_t)rbuf_len)) {
532 0 0 } else if (pushed > 0) {
551 3 0 FREETMPS;
565 1 3 if (c->tls_tunnel)
571 3 0 if (!SvROK(io_sv) || !isGV_with_GP(SvRV(io_sv)))
3 0 if (!SvROK(io_sv) || !isGV_with_GP(SvRV(io_sv)))
0 3 if (!SvROK(io_sv) || !isGV_with_GP(SvRV(io_sv)))
0 0 if (!SvROK(io_sv) || !isGV_with_GP(SvRV(io_sv)))
575 3 0 IO *io = GvIO(gv);
0 3 IO *io = GvIO(gv);
0 0 IO *io = GvIO(gv);
3 0 IO *io = GvIO(gv);
576 3 0 if (!io || !IoIFP(io))
0 3 if (!io || !IoIFP(io))
583 0 3 if (cnt > 0) {
588 0 0 if (ptr) {
590 0 0 if (!c->rbuf)
611 3 0 if (c->rbuf && cnt <= 0)
3 0 if (c->rbuf && cnt <= 0)
630 513 0 if (unlikely(!SvOK(message) || !(SvIOK(message) || SvPOK(message)))) {
78 435 if (unlikely(!SvOK(message) || !(SvIOK(message) || SvPOK(message)))) {
0 78 if (unlikely(!SvOK(message) || !(SvIOK(message) || SvPOK(message)))) {
0 513 if (unlikely(!SvOK(message) || !(SvIOK(message) || SvPOK(message)))) {
635 0 513 if (unlikely((avl+1) % 2 == 1)) {
646 4 509 if (unlikely(c->responding != RESPOND_NOT_STARTED))
648 59 450 change_responding_state(c, streaming ? RESPOND_STREAMING : RESPOND_NORMAL);
652 431 78 if (SvIOK(message))
657 0 78 if (unlikely(numtype != IS_NUMBER_IN_UV))
662 0 509 if (unlikely(!code))
670 78 431 if (likely(!SvPOK(message) || SvCUR(message) == 3)) {
1 77 if (likely(!SvPOK(message) || SvCUR(message) == 3)) {
691 506 0 c->auto_cl = (code == 204 || code == 205 || code == 304 ||
504 2 c->auto_cl = (code == 204 || code == 205 || code == 304 ||
692 506 3 (100 <= code && code <= 199)) ? 0 : 1;
504 0 (100 <= code && code <= 199)) ? 0 : 1;
504 0 (100 <= code && code <= 199)) ? 0 : 1;
703 659 509 for (i=0; i
706 659 0 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
0 659 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
659 0 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
0 659 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
659 0 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
0 659 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
710 78 581 if (unlikely(hlen == 14) && str_case_eq_fixed("content-length", hp, 14)) {
78 0 if (unlikely(hlen == 14) && str_case_eq_fixed("content-length", hp, 14)) {
711 77 1 if (likely(c->auto_cl) && !streaming)
68 9 if (likely(c->auto_cl) && !streaming)
722 59 450 if (streaming && c->is_keepalive && !has_content_length
7 52 if (streaming && c->is_keepalive && !has_content_length
6 1 if (streaming && c->is_keepalive && !has_content_length
723 1 5 && !c->is_http11 && c->auto_cl)
1 0 && !c->is_http11 && c->auto_cl)
727 493 16 if (likely(c->is_http11))
728 352 141 hdr_total += DATE_HEADER_LENGTH + (!c->is_keepalive ? 19 : 0);
729 1 15 else if (c->is_keepalive)
731 59 450 if (streaming) {
732 50 9 if (c->is_http11 && !has_content_length && c->auto_cl)
41 9 if (c->is_http11 && !has_content_length && c->auto_cl)
40 1 if (c->is_http11 && !has_content_length && c->auto_cl)
745 493 16 const char *ver = c->is_http11 ? "HTTP/1.1 " : "HTTP/1.0 ";
751 659 509 for (i=0; i
754 659 0 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
0 659 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
659 0 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
0 659 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
659 0 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
0 659 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
758 78 581 if (unlikely(hlen == 14) && str_case_eq_fixed("content-length", hp, 14)) {
78 0 if (unlikely(hlen == 14) && str_case_eq_fixed("content-length", hp, 14)) {
759 77 1 if (likely(c->auto_cl) && !streaming)
68 9 if (likely(c->auto_cl) && !streaming)
765 0 591 if (unlikely((p - SvPVX(hdr_sv)) + need > hdr_alloc)) {
768 0 0 SvGROW(hdr_sv, hdr_alloc + 1);
0 0 SvGROW(hdr_sv, hdr_alloc + 1);
778 493 16 if (likely(c->is_http11)) {
780 352 141 if (!c->is_keepalive) {
783 1 15 } else if (c->is_keepalive) {
787 59 450 if (streaming) {
788 50 9 if (c->is_http11 && !has_content_length && c->auto_cl) {
41 9 if (c->is_http11 && !has_content_length && c->auto_cl) {
40 1 if (c->is_http11 && !has_content_length && c->auto_cl) {
816 59 450 if (streaming)
828 0 450 if (c->responding != RESPOND_NORMAL)
859 0 450 if (!SvOK(body)) {
863 331 119 else if (SvROK(body)) {
865 173 158 if (SvOK(refd) && !SvROK(refd)) {
173 0 if (SvOK(refd) && !SvROK(refd)) {
869 0 158 else if (SvTYPE(refd) != SVt_PVAV) {
879 292 158 if (body_is_string) {
883 139 19 if (av_len(abody) == 0) {
885 139 0 if (elem) body_scalar = elem;
894 446 4 if (likely(c->auto_cl) && body_scalar && c->wbuf_rinq) {
16 430 if (likely(c->auto_cl) && body_scalar && c->wbuf_rinq) {
0 430 if (likely(c->auto_cl) && body_scalar && c->wbuf_rinq) {
901 430 0 if (unlikely(!hdr_sv || SvREADONLY(hdr_sv)))
0 430 if (unlikely(!hdr_sv || SvREADONLY(hdr_sv)))
910 428 2 if (likely(body_len <= 4096)) {
913 428 0 SvGROW(hdr_sv, total + 1);
428 0 SvGROW(hdr_sv, total + 1);
923 2 0 SvGROW(hdr_sv, hdr_cur + cl_len + 1);
2 0 SvGROW(hdr_sv, hdr_cur + cl_len + 1);
937 16 4 if (likely(c->auto_cl))
944 4 16 if (unlikely(!c->auto_cl)) {
947 0 16 else if (body_is_string) {
955 35 16 for (i=0; i<=amax; i++) {
957 1 34 if (unlikely(!sv)) continue;
964 16 4 if (likely(c->auto_cl)) {
984 0 3 PUSHMARK(SP);
985 0 3 mXPUSHs(newSVsv(ERRSV));
3 0 mXPUSHs(newSVsv(ERRSV));
991 3 0 sv_setsv(ERRSV, &PL_sv_undef);
1000 0 16 PUSHMARK(SP);
1001 0 16 mXPUSHs(feer_conn_2sv(c));
1002 0 16 XPUSHs(streamer);
1006 16 0 if (unlikely(SvTRUE(ERRSV))) {
0 16 if (unlikely(SvTRUE(ERRSV))) {
1010 16 0 FREETMPS;
1018 91 0 if (unlikely(!SvOK(ret) || !SvROK(ret))) {
0 91 if (unlikely(!SvOK(ret) || !SvROK(ret))) {
1019 0 0 sv_setpvs(ERRSV, "Invalid PSGI response (expected reference)");
1024 91 0 if (unlikely(!IsArrayRef(ret))) {
16 75 if (unlikely(!IsArrayRef(ret))) {
1025 16 0 if (likely(can_recurse)) {
1030 0 0 sv_setpvs(ERRSV, "PSGI attempt to recurse in a streaming callback");
1037 0 75 if (unlikely(av_len(psgi_triplet)+1 != 3)) {
1038 0 0 sv_setpvs(ERRSV, "Invalid PSGI array response (expected triplet)");
1048 75 0 if (unlikely(!msg_p || !hdrs_p || !body_p)) {
0 75 if (unlikely(!msg_p || !hdrs_p || !body_p)) {
75 0 if (unlikely(!msg_p || !hdrs_p || !body_p)) {
0 75 if (unlikely(!msg_p || !hdrs_p || !body_p)) {
1049 0 0 sv_setpvs(ERRSV, "Invalid PSGI array response (NULL element)");
1058 75 0 if (IsArrayRef(hdrs))
75 0 if (IsArrayRef(hdrs))
1061 0 0 sv_setpvs(ERRSV, "PSGI Headers must be an array-ref");
1066 75 0 if (likely(IsArrayRef(body))) {
70 5 if (likely(IsArrayRef(body))) {
1070 5 0 else if (likely(SvROK(body))) { // probably an IO::Handle-like object
1086 0 0 sv_setpvs(ERRSV, "Expected PSGI array-ref or IO::Handle-like body");
1096 54 7 if (is_writer) {
1098 1 53 if (c->poll_write_cb) {
1112 54 0 if (c->responding < RESPOND_SHUTDOWN) {
1121 0 7 if (c->poll_read_cb) {
1126 1 6 if (c->rbuf) {
1130 7 0 if (c->fd >= 0
1149 4 2 if (guard) {
1150 2 2 if (c->ext_guard) SvREFCNT_dec(c->ext_guard);
1151 4 0 c->ext_guard = SvOK(guard) ? newSVsv(guard) : NULL;
1153 6 0 return c->ext_guard ? newSVsv(c->ext_guard) : &PL_sv_undef;
1171 0 532 PUSHMARK(SP);
1173 88 444 if (server->request_cb_is_psgi) {
1175 0 88 mXPUSHs(newRV_noinc((SV*)env));
1179 0 444 mXPUSHs(feer_conn_2sv(c));
1189 532 0 if (unlikely(SvTRUE(ERRSV))) {
3 529 if (unlikely(SvTRUE(ERRSV))) {
1195 88 444 if (server->request_cb_is_psgi && likely(returned >= 1)) {
88 0 if (server->request_cb_is_psgi && likely(returned >= 1)) {
1203 88 444 if (psgi_response) {
1211 532 0 FREETMPS;
1221 24 2 SV *cb = (is_write) ? c->poll_write_cb : c->poll_read_cb;
1223 0 26 if (unlikely(cb == NULL)) return;
1232 0 26 PUSHMARK(SP);
1234 0 26 mXPUSHs(hdl);
1242 26 0 if (unlikely(SvTRUE(ERRSV))) {
0 26 if (unlikely(SvTRUE(ERRSV))) {
1243 0 0 call_died(aTHX_ c, is_write ? "write poll" : "read poll");
1251 26 0 if (SvUVX(inner)) {
1259 26 0 FREETMPS;
1271 0 11 if (unlikely(c->poll_write_cb == NULL)) return;
1278 11 0 SvREFCNT_inc_simple_void(old_rs);
1285 0 11 PUSHMARK(SP);
1286 0 11 XPUSHs(c->poll_write_cb);
1294 11 0 if (unlikely(SvTRUE(ERRSV))) {
0 11 if (unlikely(SvTRUE(ERRSV))) {
1301 0 0 if (c->poll_write_cb) {
1310 11 0 if (returned > 0)
1312 11 0 if (ret && SvMAGICAL(ret))
0 11 if (ret && SvMAGICAL(ret))
1315 11 0 if (unlikely(!ret || !SvOK(ret))) {
5 6 if (unlikely(!ret || !SvOK(ret))) {
1317 0 5 PUSHMARK(SP);
1318 0 5 XPUSHs(c->poll_write_cb);
1323 5 0 if (unlikely(SvTRUE(ERRSV))) {
0 5 if (unlikely(SvTRUE(ERRSV))) {
1324 0 0 trouble("Couldn't close body IO handle: %-p",ERRSV);
1325 0 0 sv_setsv(ERRSV, &PL_sv_undef);
1337 6 0 if (c->use_chunked)
1352 11 0 FREETMPS;
1425 0 9 if (c->tls) {
1427 0 0 if (!c->tls_tunnel) {
1434 0 0 PUSHMARK(SP);
1435 0 0 XPUSHs(sv);
1436 0 0 mXPUSHs(newSViv(c->tls_tunnel_sv1));
1442 0 0 if (unlikely(SvTRUE(ERRSV))) {
0 0 if (unlikely(SvTRUE(ERRSV))) {
1455 0 0 FREETMPS;
1464 0 9 PUSHMARK(SP);
1465 0 9 XPUSHs(sv);
1466 0 9 mXPUSHs(newSViv(c->fd));
1472 9 0 if (unlikely(SvTRUE(ERRSV))) {
0 9 if (unlikely(SvTRUE(ERRSV))) {
1482 9 0 if (likely(c->rbuf && SvOK(c->rbuf) && SvCUR(c->rbuf))) {
9 0 if (likely(c->rbuf && SvOK(c->rbuf) && SvCUR(c->rbuf))) {
9 0 if (likely(c->rbuf && SvOK(c->rbuf) && SvCUR(c->rbuf))) {
9 0 if (likely(c->rbuf && SvOK(c->rbuf) && SvCUR(c->rbuf))) {
1486 0 9 if (unlikely(!io)) {
1495 9 0 if (likely(pushed == (SSize_t)rbuf_len)) {
1497 0 0 } else if (pushed > 0) {
1516 9 0 FREETMPS;