Branch Coverage

feersum_psgi.c.inc
Criterion Covered Total %
branch 323 556 58.0


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 233 if (c->tls) return newSVpvs("https");
74 2 231 if (c->proxy_ssl) return newSVpvs("https");
75 19 212 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 209 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 49 if (psgi_env_version) return; // already initialized
131 49 211 if (unlikely(!psgi_env_version))
144 260 0 hv_stores(e, "SERVER_NAME",
146 260 0 hv_stores(e, "SERVER_PORT",
163 13 247 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 213 47 hv_stores(e, "psgi.url_scheme", scheme ? scheme : newSVpvs("http"));
182 75 185 if (c->cached_request_cb_is_psgi && c->server->psgix_io) {
75 0 if (c->cached_request_cb_is_psgi && c->server->psgix_io) {
189 0 260 if (c->trailers) {
193 1 259 if (c->proxy_tlvs) {
197 259 1 if (likely(!r->path)) feersum_set_path_and_query(aTHX_ r);
204 766 260 for (i=0; inum_headers; i++) {
224 0 724 if (unlikely(hdr->name_len > MAX_HEADER_NAME_LEN)) {
232 6220 724 for (j=0; jname_len; j++) {
242 0 724 if (unlikely(fetched == NULL)) {
247 3 721 if (unlikely(SvPOK(cur_val))) {
312 6 0 if (r->num_headers > 0)
317 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)
319 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])
321 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])
323 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])
325 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])
336 11 0 for (i = 0; i < r->num_headers; i++) {
339 5 6 if (unlikely(hdr->name_len == SvCUR(name)
5 0 if (unlikely(hdr->name_len == SvCUR(name)
359 1 6 if (unlikely(c->io_taken))
422 3 3 if (c->tls) {
424 0 3 if (!c->tls_tunnel)
431 0 3 PUSHMARK(SP);
432 0 3 XPUSHs(sv);
433 0 3 mXPUSHs(newSViv(c->tls_tunnel_sv1));
439 3 0 if (unlikely(SvTRUE(ERRSV))) {
0 3 if (unlikely(SvTRUE(ERRSV))) {
440 0 0 FREETMPS;
443 0 0 croak("Failed to create TLS tunnel IO handle: %-p", ERRSV);
446 0 3 if (unlikely(!SvROK(sv))) {
449 0 0 FREETMPS;
466 3 0 FREETMPS;
478 0 3 PUSHMARK(SP);
479 0 3 XPUSHs(sv);
480 0 3 mXPUSHs(newSViv(c->fd));
487 3 0 if (unlikely(SvTRUE(ERRSV))) {
0 3 if (unlikely(SvTRUE(ERRSV))) {
488 0 0 FREETMPS;
491 0 0 croak("Failed to create IO handle: %-p", ERRSV);
495 0 3 if (unlikely(!SvROK(sv))) {
496 0 0 FREETMPS;
507 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))) {
511 1 0 if (io) {
513 1 0 if (likely(pushed == (SSize_t)rbuf_len)) {
516 0 0 } else if (pushed > 0) {
535 3 0 FREETMPS;
549 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)))
553 3 0 IO *io = GvIO(gv);
0 3 IO *io = GvIO(gv);
0 0 IO *io = GvIO(gv);
3 0 IO *io = GvIO(gv);
554 3 0 if (!io || !IoIFP(io))
0 3 if (!io || !IoIFP(io))
561 0 3 if (cnt > 0) {
566 0 0 if (ptr) {
568 0 0 if (!c->rbuf)
589 3 0 if (c->rbuf && cnt <= 0)
3 0 if (c->rbuf && cnt <= 0)
608 469 0 if (unlikely(!SvOK(message) || !(SvIOK(message) || SvPOK(message)))) {
77 392 if (unlikely(!SvOK(message) || !(SvIOK(message) || SvPOK(message)))) {
0 77 if (unlikely(!SvOK(message) || !(SvIOK(message) || SvPOK(message)))) {
0 469 if (unlikely(!SvOK(message) || !(SvIOK(message) || SvPOK(message)))) {
613 0 469 if (unlikely((avl+1) % 2 == 1)) {
624 4 465 if (unlikely(c->responding != RESPOND_NOT_STARTED))
626 57 408 change_responding_state(c, streaming ? RESPOND_STREAMING : RESPOND_NORMAL);
630 388 77 if (SvIOK(message))
635 0 77 if (unlikely(numtype != IS_NUMBER_IN_UV))
640 0 465 if (unlikely(!code))
648 77 388 if (likely(!SvPOK(message) || SvCUR(message) == 3)) {
1 76 if (likely(!SvPOK(message) || SvCUR(message) == 3)) {
669 464 0 c->auto_cl = (code == 204 || code == 205 || code == 304 ||
462 2 c->auto_cl = (code == 204 || code == 205 || code == 304 ||
670 464 1 (100 <= code && code <= 199)) ? 0 : 1;
462 0 (100 <= code && code <= 199)) ? 0 : 1;
462 0 (100 <= code && code <= 199)) ? 0 : 1;
672 449 16 add_const_to_wbuf(c, c->is_http11 ? "HTTP/1.1 " : "HTTP/1.0 ", 9);
678 599 465 for (i=0; i
681 599 0 if (unlikely(!hdr || !SvOK(hdr))) {
0 599 if (unlikely(!hdr || !SvOK(hdr))) {
685 599 0 if (unlikely(!val || !SvOK(val))) {
0 599 if (unlikely(!val || !SvOK(val))) {
692 65 534 if (unlikely(hlen == 14) && str_case_eq_fixed("content-length", hp, 14)) {
65 0 if (unlikely(hlen == 14) && str_case_eq_fixed("content-length", hp, 14)) {
693 64 1 if (likely(c->auto_cl) && !streaming) {
56 8 if (likely(c->auto_cl) && !streaming) {
707 449 16 if (likely(c->is_http11)) {
709 322 127 if (!c->is_keepalive)
711 2 14 } else if (c->is_keepalive && !streaming)
1 1 } else if (c->is_keepalive && !streaming)
714 57 408 if (streaming) {
718 48 9 if (c->is_http11 && !has_content_length && code >= 200) {
40 8 if (c->is_http11 && !has_content_length && code >= 200) {
40 0 if (c->is_http11 && !has_content_length && code >= 200) {
726 1 16 if (c->is_keepalive && !has_content_length) c->is_keepalive = 0;
1 0 if (c->is_keepalive && !has_content_length) c->is_keepalive = 0;
735 57 408 if (streaming)
747 0 408 if (c->responding != RESPOND_NORMAL)
778 0 408 if (!SvOK(body)) {
782 291 117 else if (SvROK(body)) {
784 146 145 if (SvOK(refd) && !SvROK(refd)) {
146 0 if (SvOK(refd) && !SvROK(refd)) {
788 0 145 else if (SvTYPE(refd) != SVt_PVAV) {
798 405 3 if (likely(c->auto_cl))
803 263 145 if (body_is_string) {
811 160 145 for (i=0; i<=amax; i++) {
813 1 159 if (unlikely(!sv)) continue;
820 405 3 if (likely(c->auto_cl)) {
839 0 3 PUSHMARK(SP);
840 0 3 mXPUSHs(newSVsv(ERRSV));
3 0 mXPUSHs(newSVsv(ERRSV));
846 3 0 sv_setsv(ERRSV, &PL_sv_undef);
855 0 16 PUSHMARK(SP);
856 0 16 mXPUSHs(feer_conn_2sv(c));
857 0 16 XPUSHs(streamer);
861 16 0 if (unlikely(SvTRUE(ERRSV))) {
0 16 if (unlikely(SvTRUE(ERRSV))) {
865 16 0 FREETMPS;
873 78 0 if (unlikely(!SvOK(ret) || !SvROK(ret))) {
0 78 if (unlikely(!SvOK(ret) || !SvROK(ret))) {
874 0 0 sv_setpvs(ERRSV, "Invalid PSGI response (expected reference)");
879 78 0 if (unlikely(!IsArrayRef(ret))) {
16 62 if (unlikely(!IsArrayRef(ret))) {
880 16 0 if (likely(can_recurse)) {
885 0 0 sv_setpvs(ERRSV, "PSGI attempt to recurse in a streaming callback");
892 0 62 if (unlikely(av_len(psgi_triplet)+1 != 3)) {
893 0 0 sv_setpvs(ERRSV, "Invalid PSGI array response (expected triplet)");
903 62 0 if (unlikely(!msg_p || !hdrs_p || !body_p)) {
0 62 if (unlikely(!msg_p || !hdrs_p || !body_p)) {
62 0 if (unlikely(!msg_p || !hdrs_p || !body_p)) {
0 62 if (unlikely(!msg_p || !hdrs_p || !body_p)) {
904 0 0 sv_setpvs(ERRSV, "Invalid PSGI array response (NULL element)");
913 62 0 if (IsArrayRef(hdrs))
62 0 if (IsArrayRef(hdrs))
916 0 0 sv_setpvs(ERRSV, "PSGI Headers must be an array-ref");
921 62 0 if (likely(IsArrayRef(body))) {
57 5 if (likely(IsArrayRef(body))) {
925 5 0 else if (likely(SvROK(body))) { // probably an IO::Handle-like object
941 0 0 sv_setpvs(ERRSV, "Expected PSGI array-ref or IO::Handle-like body");
951 52 6 if (is_writer) {
953 1 51 if (c->poll_write_cb) {
967 52 0 if (c->responding < RESPOND_SHUTDOWN) {
976 0 6 if (c->poll_read_cb) {
981 1 5 if (c->rbuf) {
985 6 0 if (c->fd >= 0
1004 4 2 if (guard) {
1005 2 2 if (c->ext_guard) SvREFCNT_dec(c->ext_guard);
1006 4 0 c->ext_guard = SvOK(guard) ? newSVsv(guard) : NULL;
1008 6 0 return c->ext_guard ? newSVsv(c->ext_guard) : &PL_sv_undef;
1026 0 482 PUSHMARK(SP);
1028 75 407 if (server->request_cb_is_psgi) {
1030 0 75 mXPUSHs(newRV_noinc((SV*)env));
1034 0 407 mXPUSHs(feer_conn_2sv(c));
1044 482 0 if (unlikely(SvTRUE(ERRSV))) {
3 479 if (unlikely(SvTRUE(ERRSV))) {
1050 75 407 if (server->request_cb_is_psgi && likely(returned >= 1)) {
75 0 if (server->request_cb_is_psgi && likely(returned >= 1)) {
1058 75 407 if (psgi_response) {
1066 482 0 FREETMPS;
1076 24 2 SV *cb = (is_write) ? c->poll_write_cb : c->poll_read_cb;
1078 0 26 if (unlikely(cb == NULL)) return;
1087 0 26 PUSHMARK(SP);
1089 0 26 mXPUSHs(hdl);
1097 26 0 if (unlikely(SvTRUE(ERRSV))) {
0 26 if (unlikely(SvTRUE(ERRSV))) {
1098 0 0 call_died(aTHX_ c, is_write ? "write poll" : "read poll");
1106 26 0 if (SvUVX(inner)) {
1114 26 0 FREETMPS;
1126 0 11 if (unlikely(c->poll_write_cb == NULL)) return;
1133 11 0 SvREFCNT_inc_simple_void(old_rs);
1140 0 11 PUSHMARK(SP);
1141 0 11 XPUSHs(c->poll_write_cb);
1149 11 0 if (unlikely(SvTRUE(ERRSV))) {
0 11 if (unlikely(SvTRUE(ERRSV))) {
1156 0 0 if (c->poll_write_cb) {
1165 11 0 if (returned > 0)
1167 11 0 if (ret && SvMAGICAL(ret))
0 11 if (ret && SvMAGICAL(ret))
1170 11 0 if (unlikely(!ret || !SvOK(ret))) {
5 6 if (unlikely(!ret || !SvOK(ret))) {
1172 0 5 PUSHMARK(SP);
1173 0 5 XPUSHs(c->poll_write_cb);
1178 5 0 if (unlikely(SvTRUE(ERRSV))) {
0 5 if (unlikely(SvTRUE(ERRSV))) {
1179 0 0 trouble("Couldn't close body IO handle: %-p",ERRSV);
1180 0 0 sv_setsv(ERRSV, &PL_sv_undef);
1192 6 0 if (c->use_chunked)
1201 11 0 FREETMPS;
1278 0 9 if (c->tls) {
1280 0 0 if (!c->tls_tunnel) {
1287 0 0 PUSHMARK(SP);
1288 0 0 XPUSHs(sv);
1289 0 0 mXPUSHs(newSViv(c->tls_tunnel_sv1));
1295 0 0 if (unlikely(SvTRUE(ERRSV))) {
0 0 if (unlikely(SvTRUE(ERRSV))) {
1308 0 0 FREETMPS;
1317 0 9 PUSHMARK(SP);
1318 0 9 XPUSHs(sv);
1319 0 9 mXPUSHs(newSViv(c->fd));
1325 9 0 if (unlikely(SvTRUE(ERRSV))) {
0 9 if (unlikely(SvTRUE(ERRSV))) {
1335 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))) {
1339 0 9 if (unlikely(!io)) {
1348 9 0 if (likely(pushed == (SSize_t)rbuf_len)) {
1351 0 0 } else if (pushed > 0) {
1372 9 0 FREETMPS;