| 1 | package Net::FastCGI::Protocol; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 20 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 20 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 20 | ▶ | use Carp qw[croak]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 20 | ▶ | use Net::FastCGI qw[]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 20 | ▶ | use Net::FastCGI::Constant qw[:type :common FCGI_KEEP_CONN]; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 20 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=4 SCAR=15.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 20 | our $VERSION = '0.14'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 20 | our @EXPORT_OK = qw[ build_begin_request | |||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | build_begin_request_body | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | build_begin_request_record | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | build_end_request | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | build_end_request_body | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | build_end_request_record | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | build_header | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | build_params | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | build_record | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | build_stream | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | build_unknown_type_body | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | build_unknown_type_record | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | check_params | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | parse_begin_request_body | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | parse_end_request_body | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | parse_header | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | parse_params | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | parse_record | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | parse_record_body | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | parse_unknown_type_body | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | get_record_length | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | get_type_name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | get_role_name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | get_protocol_status_name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | is_known_type | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | is_management_type | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | is_discrete_type | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | is_stream_type ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 20 | our %EXPORT_TAGS = ( all => \@EXPORT_OK ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 20 | ▶ | my $use_pp = $ENV{NET_FASTCGI_PP} || $ENV{NET_FASTCGI_PROTOCOL_PP}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$ENV{'NET_FASTCGI_PP'} || $ENV{'NET_FASTCGI_PROTOCOL_PP'}
MC/DC0%0/2
$ENV{'NET_FASTCGI_PP'} || $ENV{'NET_FASTCGI_PROTOCOL_PP'}
$ENV{'NET_FASTCGI_PP'}
$ENV{'NET_FASTCGI_PROTOCOL_PP'}
Truth table33%1/3
A || B
A= $ENV{'NET_FASTCGI_PP'}B= $ENV{'NET_FASTCGI_PROTOCOL_PP'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 20 | ▶ | if (!$use_pp) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | require Net::FastCGI::Protocol::XS; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | $use_pp = !!$@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 20 | ▶ | if ($use_pp) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 20 | require Net::FastCGI::Protocol::PP; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 20 | Net::FastCGI::Protocol::PP->import(@EXPORT_OK); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | Net::FastCGI::Protocol::XS->import(@EXPORT_OK); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # shared between XS and PP implementation | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 20 | push @EXPORT_OK, 'dump_record', 'dump_record_body'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 20 | require Exporter; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 20 | *import = \&Exporter::import; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 20 | our $DUMP_RECORD_MAX = 78; # undocumented | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 20 | our $DUMP_RECORD_ALIGN = !!0; # undocumented | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 20 | my %ESCAPES = ( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | "\a" => "\\a", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | "\b" => "\\b", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | "\t" => "\\t", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | "\n" => "\\n", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | "\f" => "\\f", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | "\r" => "\\r", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 8 | ▶ | sub dump_record { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_record: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 8 | ▶ | goto \&dump_record_body if (@_ == 2 || @_ == 3); # deprecated | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ == 2 or @_ == 3
MC/DC100%2/2
@_ == 2 or @_ == 3
@_ == 2
@_ == 3
Truth table100%3/3
A or B
A= @_ == 2B= @_ == 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 6 | ▶ | @_ == 1 || croak(q/Usage: dump_record(octets)/); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 5 | my $len = &get_record_length; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 5 | ▶ | ($len && $len <= length $_[0] && vec($_[0], 0, 8) == FCGI_VERSION_1) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$len and $len <= length $_[0] and vec($_[0], 0, 8) == 1
$len and $len <= length $_[0]
MC/DC100%3/3
$len and $len <= length $_[0] and vec($_[0], 0, 8) == 1
$len
$len <= length $_[0]
vec($_[0], 0, 8) == 1
Truth table100%4/4
A and B and C
A= $lenB= $len <= length $_[0]C= vec($_[0], 0, 8) == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | || return '{Malformed FCGI_Record}'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 1 | return dump_record_body(&parse_record); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 65 | ▶ | sub dump_record_body { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump_record_body: called CC=33 SCAR=35.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 65 | ▶ | @_ == 2 || @_ == 3 || croak(q/Usage: dump_record_body(type, request_id [, content])/); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ == 2 or @_ == 3
MC/DC100%2/2
@_ == 2 or @_ == 3
@_ == 2
@_ == 3
Truth table100%3/3
A or B
A= @_ == 2B= @_ == 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 63 | my ($type, $request_id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 63 | ▶ | my $content_length = defined $_[2] ? length $_[2] : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 63 | ▶ | my $max = $DUMP_RECORD_MAX > 0 ? $DUMP_RECORD_MAX : FCGI_MAX_CONTENT_LEN; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 63 | my $out = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 63 | ▶ | if ( $type == FCGI_PARAMS | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition100%6/6
$type == 4 or $type == 9 or $type == 10
$type == 4 or $type == 9
MC/DC100%3/3
$type == 4 or $type == 9 or $type == 10
$type == 4
$type == 9
$type == 10
Truth table100%4/4
A or B or C
A= $type == 4B= $type == 9C= $type == 10
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | || $type == FCGI_GET_VALUES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | || $type == FCGI_GET_VALUES_RESULT) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 21 | ▶ | if ($content_length == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | $out = q[""]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | elsif (check_params($_[2])) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 12 | my ($off, $klen, $vlen) = (0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 12 | ▶ | while ($off < $content_length) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 12 | my $pos = $off; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 12 | for ($klen, $vlen) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 24 | $_ = vec($_[2], $off, 8); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 24 | ▶ | $_ = vec(substr($_[2], $off, 4), 0, 32) & 0x7FFF_FFFF | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | if $_ > 0x7F; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 24 | ▶ | $off += $_ > 0x7F ? 4 : 1; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 12 | my $head = substr($_[2], $pos, $off - $pos); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 12 | $head =~ s/(.)/sprintf('\\%.3o',ord($1))/egs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 12 | $out .= $head; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 12 | my $body = substr($_[2], $off, $klen + $vlen); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 12 | for ($body) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 12 | s/([\\\"])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 12 | s/([\a\b\t\n\f\r])/$ESCAPES{$1}/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 12 | s/([^\x20-\x7E])/sprintf('\\x%.2X',ord($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 12 | $out .= $body; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 12 | $off += $klen + $vlen; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 12 | ▶ | last if $off > $max; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 12 | ▶ | substr($out, $max - 5) = ' ... ' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | if length $out > $max; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 12 | $out = qq["$out"]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 3 | $out = 'Malformed FCGI_NameValuePair(s)'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ▶ | elsif ( $type == FCGI_BEGIN_REQUEST | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%6/6
$type == 1 or $type == 3 or $type == 11
$type == 1 or $type == 3
MC/DC100%3/3
$type == 1 or $type == 3 or $type == 11
$type == 1
$type == 3
$type == 11
Truth table100%4/4
A or B or C
A= $type == 1B= $type == 3C= $type == 11
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | || $type == FCGI_END_REQUEST | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | || $type == FCGI_UNKNOWN_TYPE) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 30 | ▶ | if ($content_length != 8) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 9 | ▶ | my $name = $type == FCGI_BEGIN_REQUEST ? 'FCGI_BeginRequestBody' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | : $type == FCGI_END_REQUEST ? 'FCGI_EndRequestBody' | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | : 'FCGI_UnknownTypeBody'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 9 | $out = sprintf '{Malformed %s (expected 8 octets got %d)}', $name, $content_length; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | elsif ($type == FCGI_BEGIN_REQUEST) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 4 | my ($role, $flags) = parse_begin_request_body($_[2]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 4 | ▶ | if ($flags != 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 3 | my @set; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | ▶ | if ($flags & FCGI_KEEP_CONN) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 2 | $flags &= ~FCGI_KEEP_CONN; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 2 | push @set, 'FCGI_KEEP_CONN'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 3 | ▶ | if ($flags) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 2 | push @set, sprintf '0x%.2X', $flags; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | $flags = join '|', @set; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 4 | $out = sprintf '{%s, %s}', get_role_name($role), $flags; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | elsif($type == FCGI_END_REQUEST) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 5 | my ($astatus, $pstatus) = parse_end_request_body($_[2]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 5 | $out = sprintf '{%d, %s}', $astatus, get_protocol_status_name($pstatus); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 12 | my $unknown_type = parse_unknown_type_body($_[2]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 12 | $out = sprintf '{%s}', get_type_name($unknown_type); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | elsif ($content_length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 6 | my $looks_like_binary = do { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 6 | my $count = () = $_[2] =~ /[\r\n\t\x20-\x7E]/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 6 | ($count / $content_length) < 0.7; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 6 | $out = substr($_[2], 0, $max + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 6 | for ($out) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 6 | ▶ | if ($looks_like_binary) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 3 | s/(.)/sprintf('\\x%.2X',ord($1))/egs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 3 | s/([\\\"])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 3 | s/([\a\b\t\n\f\r])/$ESCAPES{$1}/g; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 3 | s/([^\x20-\x7E])/sprintf('\\x%.2X',ord($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 6 | ▶ | substr($out, $max - 5) = ' ... ' | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | if length $out > $max; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 6 | $out = qq["$out"]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 6 | $out = q[""]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 63 | my $name = get_type_name($type); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 63 | my $width = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 63 | ▶ | $width = 27 - length $name # length("FCGI_GET_VALUES_RESULT") == 22 | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | if $DUMP_RECORD_ALIGN; # + length(0xFFFF) == 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 63 | return sprintf '{%s, %*d, %s}', $name, $width, $request_id, $out; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 20 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||