Branch Coverage

feersum_psgi.c.inc
Criterion Covered Total %
branch 374 630 59.3


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 38 240 if (c->tls) return newSVpvs("https");
74 2 238 if (c->proxy_ssl) return newSVpvs("https");
75 19 219 if (c->proxy_proto_version > 0 && c->proxy_dst_port == 443)
5 14 if (c->proxy_proto_version > 0 && c->proxy_dst_port == 443)
77 17 216 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 50 if (psgi_env_version) return; // already initialized
131 50 217 if (unlikely(!psgi_env_version))
144 267 0 hv_stores(e, "SERVER_NAME",
146 267 0 hv_stores(e, "SERVER_PORT",
163 13 254 if (c->cached_use_reverse_proxy) {
165 5 8 hv_stores(e, "REMOTE_ADDR", fwd_addr ? fwd_addr : SvREFCNT_inc_simple_NN(c->remote_addr));
173 220 47 hv_stores(e, "psgi.url_scheme", scheme ? scheme : newSVpvs("http"));
182 82 185 if (c->cached_request_cb_is_psgi && c->server->psgix_io) {
82 0 if (c->cached_request_cb_is_psgi && c->server->psgix_io) {
189 0 267 if (c->trailers) {
193 1 266 if (c->proxy_tlvs) {
197 266 1 if (likely(!r->path)) feersum_set_path_and_query(aTHX_ r);
204 787 267 for (i=0; inum_headers; i++) {
223 0 745 if (unlikely(hdr->name_len > MAX_HEADER_NAME_LEN)) {
231 6388 745 for (j=0; jname_len; j++) {
241 0 745 if (unlikely(fetched == NULL)) {
246 3 742 if (unlikely(SvPOK(cur_val))) {
311 6 0 if (r->num_headers > 0)
316 0 3 COPY_NORM_HEADER(n)
22 3 COPY_NORM_HEADER(n)
0 3 COPY_NORM_HEADER(n)
0 3 COPY_NORM_HEADER(n)
3 1 COPY_NORM_HEADER(n)
318 0 3 COPY_NORM_HEADER(ascii_lower[(unsigned char)n])
22 3 COPY_NORM_HEADER(ascii_lower[(unsigned char)n])
0 3 COPY_NORM_HEADER(ascii_lower[(unsigned char)n])
0 3 COPY_NORM_HEADER(ascii_lower[(unsigned char)n])
3 1 COPY_NORM_HEADER(ascii_lower[(unsigned char)n])
320 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])
3 1 COPY_NORM_HEADER(ascii_upper[(unsigned char)n])
322 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])
8 2 COPY_NORM_HEADER(ascii_lower_dash[(unsigned char)n])
324 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])
3 1 COPY_NORM_HEADER(ascii_upper_dash[(unsigned char)n])
335 11 0 for (i = 0; i < r->num_headers; i++) {
338 5 6 if (unlikely(hdr->name_len == SvCUR(name)
5 0 if (unlikely(hdr->name_len == SvCUR(name)
358 1 6 if (unlikely(c->io_taken))
421 3 3 if (c->tls) {
423 0 3 if (!c->tls_tunnel)
430 0 3 PUSHMARK(SP);
431 0 3 XPUSHs(sv);
432 0 3 mXPUSHs(newSViv(c->tls_tunnel_sv1));
438 3 0 if (unlikely(SvTRUE(ERRSV))) {
0 3 if (unlikely(SvTRUE(ERRSV))) {
439 0 0 FREETMPS;
442 0 0 croak("Failed to create TLS tunnel IO handle: %-p", ERRSV);
445 0 3 if (unlikely(!SvROK(sv))) {
448 0 0 FREETMPS;
465 3 0 FREETMPS;
477 0 3 PUSHMARK(SP);
478 0 3 XPUSHs(sv);
479 0 3 mXPUSHs(newSViv(c->fd));
486 3 0 if (unlikely(SvTRUE(ERRSV))) {
0 3 if (unlikely(SvTRUE(ERRSV))) {
487 0 0 FREETMPS;
490 0 0 croak("Failed to create IO handle: %-p", ERRSV);
494 0 3 if (unlikely(!SvROK(sv))) {
495 0 0 FREETMPS;
506 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))) {
510 1 0 if (io) {
512 1 0 if (likely(pushed == (SSize_t)rbuf_len)) {
515 0 0 } else if (pushed > 0) {
534 3 0 FREETMPS;
548 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)))
552 3 0 IO *io = GvIO(gv);
0 3 IO *io = GvIO(gv);
0 0 IO *io = GvIO(gv);
3 0 IO *io = GvIO(gv);
553 3 0 if (!io || !IoIFP(io))
0 3 if (!io || !IoIFP(io))
560 0 3 if (cnt > 0) {
565 0 0 if (ptr) {
567 0 0 if (!c->rbuf)
588 3 0 if (c->rbuf && cnt <= 0)
3 0 if (c->rbuf && cnt <= 0)
607 480 0 if (unlikely(!SvOK(message) || !(SvIOK(message) || SvPOK(message)))) {
78 402 if (unlikely(!SvOK(message) || !(SvIOK(message) || SvPOK(message)))) {
0 78 if (unlikely(!SvOK(message) || !(SvIOK(message) || SvPOK(message)))) {
0 480 if (unlikely(!SvOK(message) || !(SvIOK(message) || SvPOK(message)))) {
612 0 480 if (unlikely((avl+1) % 2 == 1)) {
623 4 476 if (unlikely(c->responding != RESPOND_NOT_STARTED))
625 58 418 change_responding_state(c, streaming ? RESPOND_STREAMING : RESPOND_NORMAL);
629 398 78 if (SvIOK(message))
634 0 78 if (unlikely(numtype != IS_NUMBER_IN_UV))
639 0 476 if (unlikely(!code))
647 78 398 if (likely(!SvPOK(message) || SvCUR(message) == 3)) {
1 77 if (likely(!SvPOK(message) || SvCUR(message) == 3)) {
668 475 0 c->auto_cl = (code == 204 || code == 205 || code == 304 ||
473 2 c->auto_cl = (code == 204 || code == 205 || code == 304 ||
669 475 1 (100 <= code && code <= 199)) ? 0 : 1;
473 0 (100 <= code && code <= 199)) ? 0 : 1;
473 0 (100 <= code && code <= 199)) ? 0 : 1;
680 615 476 for (i=0; i
683 615 0 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
0 615 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
615 0 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
0 615 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
615 0 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
0 615 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
687 66 549 if (unlikely(hlen == 14) && str_case_eq_fixed("content-length", hp, 14)) {
66 0 if (unlikely(hlen == 14) && str_case_eq_fixed("content-length", hp, 14)) {
688 65 1 if (likely(c->auto_cl) && !streaming)
56 9 if (likely(c->auto_cl) && !streaming)
696 460 16 if (likely(c->is_http11))
697 329 131 hdr_total += DATE_HEADER_LENGTH + (!c->is_keepalive ? 19 : 0);
698 2 14 else if (c->is_keepalive && !streaming)
1 1 else if (c->is_keepalive && !streaming)
700 58 418 if (streaming) {
701 49 9 if (c->is_http11 && !has_content_length && code >= 200)
40 9 if (c->is_http11 && !has_content_length && code >= 200)
40 0 if (c->is_http11 && !has_content_length && code >= 200)
714 460 16 const char *ver = c->is_http11 ? "HTTP/1.1 " : "HTTP/1.0 ";
720 615 476 for (i=0; i
723 615 0 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
0 615 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
615 0 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
0 615 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
615 0 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
0 615 if (unlikely(!hdr || !SvOK(hdr) || !val || !SvOK(val)))
727 66 549 if (unlikely(hlen == 14) && str_case_eq_fixed("content-length", hp, 14)) {
66 0 if (unlikely(hlen == 14) && str_case_eq_fixed("content-length", hp, 14)) {
728 65 1 if (likely(c->auto_cl) && !streaming)
56 9 if (likely(c->auto_cl) && !streaming)
734 0 559 if (unlikely((p - SvPVX(hdr_sv)) + need > hdr_alloc)) {
737 0 0 SvGROW(hdr_sv, hdr_alloc + 1);
0 0 SvGROW(hdr_sv, hdr_alloc + 1);
747 460 16 if (likely(c->is_http11)) {
749 329 131 if (!c->is_keepalive) {
752 2 14 } else if (c->is_keepalive && !streaming) {
1 1 } else if (c->is_keepalive && !streaming) {
756 58 418 if (streaming) {
757 49 9 if (c->is_http11 && !has_content_length && code >= 200) {
40 9 if (c->is_http11 && !has_content_length && code >= 200) {
40 0 if (c->is_http11 && !has_content_length && code >= 200) {
764 2 16 if (c->is_keepalive && !has_content_length) c->is_keepalive = 0;
1 1 if (c->is_keepalive && !has_content_length) c->is_keepalive = 0;
786 58 418 if (streaming)
798 0 418 if (c->responding != RESPOND_NORMAL)
829 0 418 if (!SvOK(body)) {
833 301 117 else if (SvROK(body)) {
835 149 152 if (SvOK(refd) && !SvROK(refd)) {
149 0 if (SvOK(refd) && !SvROK(refd)) {
839 0 152 else if (SvTYPE(refd) != SVt_PVAV) {
849 266 152 if (body_is_string) {
853 133 19 if (av_len(abody) == 0) {
855 133 0 if (elem) body_scalar = elem;
864 415 3 if (likely(c->auto_cl) && body_scalar && c->wbuf_rinq) {
16 399 if (likely(c->auto_cl) && body_scalar && c->wbuf_rinq) {
0 399 if (likely(c->auto_cl) && body_scalar && c->wbuf_rinq) {
871 399 0 if (unlikely(!hdr_sv || SvREADONLY(hdr_sv)))
0 399 if (unlikely(!hdr_sv || SvREADONLY(hdr_sv)))
880 397 2 if (likely(body_len <= 4096)) {
883 397 0 SvGROW(hdr_sv, total + 1);
397 0 SvGROW(hdr_sv, total + 1);
893 2 0 SvGROW(hdr_sv, hdr_cur + cl_len + 1);
2 0 SvGROW(hdr_sv, hdr_cur + cl_len + 1);
907 16 3 if (likely(c->auto_cl))
912 0 19 if (body_is_string) {
920 35 19 for (i=0; i<=amax; i++) {
922 1 34 if (unlikely(!sv)) continue;
929 16 3 if (likely(c->auto_cl)) {
949 0 3 PUSHMARK(SP);
950 0 3 mXPUSHs(newSVsv(ERRSV));
3 0 mXPUSHs(newSVsv(ERRSV));
956 3 0 sv_setsv(ERRSV, &PL_sv_undef);
965 0 16 PUSHMARK(SP);
966 0 16 mXPUSHs(feer_conn_2sv(c));
967 0 16 XPUSHs(streamer);
971 16 0 if (unlikely(SvTRUE(ERRSV))) {
0 16 if (unlikely(SvTRUE(ERRSV))) {
975 16 0 FREETMPS;
983 85 0 if (unlikely(!SvOK(ret) || !SvROK(ret))) {
0 85 if (unlikely(!SvOK(ret) || !SvROK(ret))) {
984 0 0 sv_setpvs(ERRSV, "Invalid PSGI response (expected reference)");
989 85 0 if (unlikely(!IsArrayRef(ret))) {
16 69 if (unlikely(!IsArrayRef(ret))) {
990 16 0 if (likely(can_recurse)) {
995 0 0 sv_setpvs(ERRSV, "PSGI attempt to recurse in a streaming callback");
1002 0 69 if (unlikely(av_len(psgi_triplet)+1 != 3)) {
1003 0 0 sv_setpvs(ERRSV, "Invalid PSGI array response (expected triplet)");
1013 69 0 if (unlikely(!msg_p || !hdrs_p || !body_p)) {
0 69 if (unlikely(!msg_p || !hdrs_p || !body_p)) {
69 0 if (unlikely(!msg_p || !hdrs_p || !body_p)) {
0 69 if (unlikely(!msg_p || !hdrs_p || !body_p)) {
1014 0 0 sv_setpvs(ERRSV, "Invalid PSGI array response (NULL element)");
1023 69 0 if (IsArrayRef(hdrs))
69 0 if (IsArrayRef(hdrs))
1026 0 0 sv_setpvs(ERRSV, "PSGI Headers must be an array-ref");
1031 69 0 if (likely(IsArrayRef(body))) {
64 5 if (likely(IsArrayRef(body))) {
1035 5 0 else if (likely(SvROK(body))) { // probably an IO::Handle-like object
1051 0 0 sv_setpvs(ERRSV, "Expected PSGI array-ref or IO::Handle-like body");
1061 53 6 if (is_writer) {
1063 1 52 if (c->poll_write_cb) {
1077 53 0 if (c->responding < RESPOND_SHUTDOWN) {
1086 0 6 if (c->poll_read_cb) {
1091 1 5 if (c->rbuf) {
1095 6 0 if (c->fd >= 0
1114 4 2 if (guard) {
1115 2 2 if (c->ext_guard) SvREFCNT_dec(c->ext_guard);
1116 4 0 c->ext_guard = SvOK(guard) ? newSVsv(guard) : NULL;
1118 6 0 return c->ext_guard ? newSVsv(c->ext_guard) : &PL_sv_undef;
1136 0 493 PUSHMARK(SP);
1138 82 411 if (server->request_cb_is_psgi) {
1140 0 82 mXPUSHs(newRV_noinc((SV*)env));
1144 0 411 mXPUSHs(feer_conn_2sv(c));
1154 493 0 if (unlikely(SvTRUE(ERRSV))) {
3 490 if (unlikely(SvTRUE(ERRSV))) {
1160 82 411 if (server->request_cb_is_psgi && likely(returned >= 1)) {
82 0 if (server->request_cb_is_psgi && likely(returned >= 1)) {
1168 82 411 if (psgi_response) {
1176 493 0 FREETMPS;
1186 24 2 SV *cb = (is_write) ? c->poll_write_cb : c->poll_read_cb;
1188 0 26 if (unlikely(cb == NULL)) return;
1197 0 26 PUSHMARK(SP);
1199 0 26 mXPUSHs(hdl);
1207 26 0 if (unlikely(SvTRUE(ERRSV))) {
0 26 if (unlikely(SvTRUE(ERRSV))) {
1208 0 0 call_died(aTHX_ c, is_write ? "write poll" : "read poll");
1216 26 0 if (SvUVX(inner)) {
1224 26 0 FREETMPS;
1236 0 11 if (unlikely(c->poll_write_cb == NULL)) return;
1243 11 0 SvREFCNT_inc_simple_void(old_rs);
1250 0 11 PUSHMARK(SP);
1251 0 11 XPUSHs(c->poll_write_cb);
1259 11 0 if (unlikely(SvTRUE(ERRSV))) {
0 11 if (unlikely(SvTRUE(ERRSV))) {
1266 0 0 if (c->poll_write_cb) {
1275 11 0 if (returned > 0)
1277 11 0 if (ret && SvMAGICAL(ret))
0 11 if (ret && SvMAGICAL(ret))
1280 11 0 if (unlikely(!ret || !SvOK(ret))) {
5 6 if (unlikely(!ret || !SvOK(ret))) {
1282 0 5 PUSHMARK(SP);
1283 0 5 XPUSHs(c->poll_write_cb);
1288 5 0 if (unlikely(SvTRUE(ERRSV))) {
0 5 if (unlikely(SvTRUE(ERRSV))) {
1289 0 0 trouble("Couldn't close body IO handle: %-p",ERRSV);
1290 0 0 sv_setsv(ERRSV, &PL_sv_undef);
1302 6 0 if (c->use_chunked)
1317 11 0 FREETMPS;
1390 0 9 if (c->tls) {
1392 0 0 if (!c->tls_tunnel) {
1399 0 0 PUSHMARK(SP);
1400 0 0 XPUSHs(sv);
1401 0 0 mXPUSHs(newSViv(c->tls_tunnel_sv1));
1407 0 0 if (unlikely(SvTRUE(ERRSV))) {
0 0 if (unlikely(SvTRUE(ERRSV))) {
1420 0 0 FREETMPS;
1429 0 9 PUSHMARK(SP);
1430 0 9 XPUSHs(sv);
1431 0 9 mXPUSHs(newSViv(c->fd));
1437 9 0 if (unlikely(SvTRUE(ERRSV))) {
0 9 if (unlikely(SvTRUE(ERRSV))) {
1447 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))) {
1451 0 9 if (unlikely(!io)) {
1460 9 0 if (likely(pushed == (SSize_t)rbuf_len)) {
1462 0 0 } else if (pushed > 0) {
1481 9 0 FREETMPS;