| 1 | package HTTP::Message; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 17 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 17 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 17 | our $VERSION = '7.02'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 17 | require HTTP::Headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 17 | require Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 17 | our $MAXIMUM_BODY_SIZE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 17 | my $CRLF = "\015\012"; # "\r\n" is not portable | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 17 | ▶ | unless ($HTTP::URI_CLASS) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 17 | ▶ | if ($ENV{PERL_HTTP_URI_CLASS} | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ENV{"PERL_HTTP_URI_CLASS"} and $ENV{"PERL_HTTP_URI_CLASS"} =~ /^([\w:]+)$/
MC/DC0%0/2
$ENV{"PERL_HTTP_URI_CLASS"} and $ENV{"PERL_HTTP_URI_CLASS"} =~ /^([\w:]+)$/
$ENV{"PERL_HTTP_URI_CLASS"}
$ENV{"PERL_HTTP_URI_CLASS"} =~ /^([\w:]+)$/
Truth table33%1/3
A and B
A= $ENV{"PERL_HTTP_URI_CLASS"}B= $ENV{"PERL_HTTP_URI_CLASS"} =~ /^([\w:]+)$/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | && $ENV{PERL_HTTP_URI_CLASS} =~ /^([\w:]+)$/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | $HTTP::URI_CLASS = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 17 | $HTTP::URI_CLASS = "URI"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 17 | ▶ | eval "require $HTTP::URI_CLASS"; die $@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | *_utf8_downgrade = defined(&utf8::downgrade) ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 227 | ▶ | utf8::downgrade($_[0], 1) or | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | Carp::croak("HTTP::Message content must be bytes") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | : | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ▶ | sub { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 17 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 186 | ▶ | my($class, $header, $content) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 186 | ▶ | if (defined $header) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 101 | ▶ | Carp::croak("Bad header argument") unless ref $header; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 100 | ▶ | if (ref($header) eq "ARRAY") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 79 | $header = HTTP::Headers->new(@$header); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 21 | $header = $header->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 85 | $header = HTTP::Headers->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 185 | ▶ | if (defined $content) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 96 | _utf8_downgrade($content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 89 | $content = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 184 | bless { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | '_headers' => $header, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | '_content' => $content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | '_max_body_size' => $HTTP::Message::MAXIMUM_BODY_SIZE, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | }, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | sub parse | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 47 | ▶ | my($class, $str) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 47 | my @hdr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 47 | while (1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 81 | ▶ | if ($str =~ s/^([^\s:]+)[ \t]*: ?(.*)\n?//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 29 | push(@hdr, $1, $2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 29 | $hdr[-1] =~ s/\r\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ▶ | elsif (@hdr && $str =~ s/^([ \t].*)\n?//) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
@hdr and $str =~ s/^([ \t].*)\n?//
MC/DC100%2/2
@hdr and $str =~ s/^([ \t].*)\n?//
@hdr
$str =~ s/^([ \t].*)\n?//
Truth table100%3/3
A and B
A= @hdrB= $str =~ s/^([ \t].*)\n?//
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 5 | $hdr[-1] .= "\n$1"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 5 | $hdr[-1] =~ s/\r\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 47 | $str =~ s/^\r?\n//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 47 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 47 | local $HTTP::Headers::TRANSLATE_UNDERSCORE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 47 | new($class, \@hdr, $str); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | sub clone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 8 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 8 | my $clone = HTTP::Message->new($self->headers, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | $self->content); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 8 | $clone->protocol($self->protocol); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 8 | $clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | sub clear { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | $self->{_headers}->clear; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | $self->content(""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 4 | delete $self->{_parts}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | sub protocol { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 78 | ▶ | shift->_elem('_protocol', @_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
protocol: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | sub headers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 1125 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
headers: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # recalculation of _content might change headers, so we | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # need to force it now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1125 | ▶ | $self->_content unless exists $self->{_content}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 1125 | $self->{_headers}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | sub headers_as_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | ▶ | shift->headers->as_string(@_); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
headers_as_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | sub content { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 348 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 348 | ▶ | if (defined(wantarray)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 243 | ▶ | $self->_content unless exists $self->{_content}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 243 | my $old = $self->{_content}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 243 | ▶ | $old = $$old if ref($old) eq "SCALAR"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 243 | ▶ | &_set_content if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 243 | return $old; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 105 | ▶ | if (@_ > 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 103 | &_set_content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | ▶ | Carp::carp("Useless content call in void context") if $^W; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | sub _set_content { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 119 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_content: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 119 | _utf8_downgrade($_[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 118 | ▶ | if (!ref($_[1]) && ref($self->{_content}) eq "SCALAR") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not ref $_[1] and ref $self->{"_content"} eq "SCALAR"
MC/DC100%2/2
not ref $_[1] and ref $self->{"_content"} eq "SCALAR"
not ref $_[1]
ref $self->{"_content"} eq "SCALAR"
Truth table100%3/3
not(A) and B
A= not ref $_[1]B= ref $self->{"_content"} eq "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 3 | ▶ | ${$self->{_content}} = defined( $_[1] ) ? $_[1] : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 115 | ▶ | die "Can't set content to be a scalar reference" if ref($_[1]) eq "SCALAR"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 114 | ▶ | $self->{_content} = defined( $_[1] ) ? $_[1] : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 114 | delete $self->{_content_ref}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 116 | ▶ | delete $self->{_parts} unless $_[2]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | sub add_content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_content: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 12 | ▶ | $self->_content unless exists $self->{_content}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 12 | my $chunkref = \$_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 12 | ▶ | $chunkref = $$chunkref if ref($$chunkref); # legacy | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 12 | _utf8_downgrade($$chunkref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 11 | my $ref = ref($self->{_content}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 11 | ▶ | if (!$ref) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 9 | $self->{_content} .= $$chunkref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | elsif ($ref eq "SCALAR") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 1 | ${$self->{_content}} .= $$chunkref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | Carp::croak("Can't append to $ref content"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 10 | delete $self->{_parts}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | sub add_content_utf8 { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 2 | ▶ | my($self, $buf) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_content_utf8: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 2 | utf8::upgrade($buf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 2 | utf8::encode($buf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 2 | $self->add_content($buf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | sub content_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 137 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content_ref: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 137 | ▶ | $self->_content unless exists $self->{_content}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 137 | delete $self->{_parts}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 137 | my $old = \$self->{_content}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 137 | my $old_cref = $self->{_content_ref}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 137 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 6 | my $new = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 6 | ▶ | Carp::croak("Setting content_ref to a non-ref") unless ref($new); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 5 | delete $self->{_content}; # avoid modifying $$old | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 5 | $self->{_content} = $new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 5 | $self->{_content_ref}++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 136 | ▶ | $old = $$old if $old_cref; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 136 | return $old; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | sub content_charset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 52 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content_charset: called CC=30 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 52 | ▶ | if (my $charset = $self->content_type_charset) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | return $charset; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # time to start guessing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 51 | my $cref = $self->decoded_content(ref => 1, charset => "none"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # Unicode BOM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 51 | for ($$cref) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 51 | ▶ | return "UTF-8" if /^\xEF\xBB\xBF/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 49 | ▶ | return "UTF-32LE" if /^\xFF\xFE\x00\x00/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 48 | ▶ | return "UTF-32BE" if /^\x00\x00\xFE\xFF/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 47 | ▶ | return "UTF-16LE" if /^\xFF\xFE/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 43 | ▶ | return "UTF-16BE" if /^\xFE\xFF/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 42 | ▶ | if ($self->content_is_xml) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # http://www.w3.org/TR/2006/REC-xml-20060816/#sec-guessing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # XML entity not accompanied by external encoding information and not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | # in UTF-8 or UTF-16 encoding must begin with an XML encoding declaration, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | # in which the first characters must be '<?xml' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 15 | for ($$cref) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 15 | ▶ | return "UTF-32BE" if /^\x00\x00\x00</; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 14 | ▶ | return "UTF-32LE" if /^<\x00\x00\x00/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 13 | ▶ | return "UTF-16BE" if /^(?:\x00\s)*\x00</; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 12 | ▶ | return "UTF-16LE" if /^(?:\s\x00)*<\x00/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 11 | ▶ | if (/^\s*(<\?xml[^\x00]*?\?>)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 4 | ▶ | if ($1 =~ /\sencoding\s*=\s*(["'])(.*?)\1/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 4 | my $enc = $2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 4 | $enc =~ s/^\s+//; $enc =~ s/\s+\z//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 4 | ▶ | return $enc if $enc; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 8 | return "UTF-8"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | elsif ($self->content_is_html) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | # look for <META charset="..."> or <META content="..."> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | # http://dev.w3.org/html5/spec/Overview.html#determining-the-character-encoding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 4 | require IO::HTML; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # Use relaxed search to match previous versions of HTTP::Message: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 4 | my $encoding = IO::HTML::find_charset_in($$cref, { encoding => 1, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | need_pragma => 0 }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 4 | ▶ | return $encoding->mime_name if $encoding; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | elsif ($self->content_type eq "application/json") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 6 | for ($$cref) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | # RFC 4627, ch 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | 6 | ▶ | return "UTF-32BE" if /^\x00\x00\x00./s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 5 | ▶ | return "UTF-32LE" if /^.\x00\x00\x00/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 3 | ▶ | return "UTF-16BE" if /^\x00.\x00./s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 2 | ▶ | return "UTF-16LE" if /^.\x00.\x00/s; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | return "UTF-8"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 18 | ▶ | if ($self->content_type =~ /^text\//) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 17 | for ($$cref) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 17 | ▶ | if (length) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 16 | ▶ | return "US-ASCII" unless /[\x80-\xFF]/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 3 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 3 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 3 | Encode::decode_utf8($_, Encode::FB_CROAK() | Encode::LEAVE_SRC()); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 3 | ▶ | return "UTF-8" unless $@; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 1 | return "ISO-8859-1"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 2 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | sub max_body_size { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 133 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_body_size: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 133 | my $old = $self->{_max_body_size}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 133 | ▶ | $self->_set_max_body_size($_[1]) if @_ > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 133 | return $old; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | sub _set_max_body_size { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 6 | ▶ | my $self = $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_max_body_size: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 6 | $self->{_max_body_size} = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | sub decoded_content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 118 | ▶ | my($self, %opt) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decoded_content: called CC=63 SCAR=41.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 118 | my $content_ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | my $content_ref_iscopy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 118 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 118 | $content_ref = $self->content_ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 118 | ▶ | die "Can't decode ref content" if ref($content_ref) ne "SCALAR"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | my $content_limit = exists $opt{ max_body_size } ? $opt{ max_body_size } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 118 | ▶ | : defined $self->max_body_size ? $self->max_body_size | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | : undef | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | ; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 118 | my %limiter_options; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 118 | ▶ | if( defined $content_limit ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 6 | %limiter_options = (LimitOutput => 1, Bufsize => $content_limit); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 118 | ▶ | if (my $h = $self->header("Content-Encoding")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 60 | $h =~ s/^\s+//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 60 | $h =~ s/\s+$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | 60 | for my $ce (reverse split(/\s*,\s*/, lc($h))) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 105 | ▶ | next unless $ce; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 105 | ▶ | next if $ce eq "identity" || $ce eq "none"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ce eq "identity" or $ce eq "none"
MC/DC100%2/2
$ce eq "identity" or $ce eq "none"
$ce eq "identity"
$ce eq "none"
Truth table100%3/3
A or B
A= $ce eq "identity"B= $ce eq "none"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | 101 | ▶ | if ($ce eq "gzip" || $ce eq "x-gzip") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
Condition100%3/3
$ce eq "gzip" or $ce eq "x-gzip"
MC/DC100%2/2
$ce eq "gzip" or $ce eq "x-gzip"
$ce eq "gzip"
$ce eq "x-gzip"
Truth table100%3/3
A or B
A= $ce eq "gzip"B= $ce eq "x-gzip"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 30 | require Compress::Raw::Zlib; # 'WANT_GZIP_OR_ZLIB', 'Z_BUF_ERROR'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 30 | ▶ | if( ! $content_ref_iscopy and keys %limiter_options) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $content_ref_iscopy and keys %limiter_options
MC/DC100%2/2
not $content_ref_iscopy and keys %limiter_options
not $content_ref_iscopy
keys %limiter_options
Truth table100%3/3
not(A) and B
A= not $content_ref_iscopyB= keys %limiter_options
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | # Create a copy of the input because Zlib will overwrite it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | # :-( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 2 | my $input = "$$content_ref"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 2 | $content_ref = \$input; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 2 | $content_ref_iscopy++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 30 | my ($i, $status) = Compress::Raw::Zlib::Inflate->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | %limiter_options, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | ConsumeInput => 0, # overridden by Zlib if we have %limiter_options :-( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | WindowBits => Compress::Raw::Zlib::WANT_GZIP_OR_ZLIB(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 30 | my $res = $i->inflate( $content_ref, \my $output ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 30 | ▶ | $res == Compress::Raw::Zlib::Z_BUF_ERROR() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | and Carp::croak("Decoded content would be larger than $content_limit octets"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 28 | ▶ | $res == Compress::Raw::Zlib::Z_OK() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$res == Compress::Raw::Zlib::Z_OK() or $res == Compress::Raw::Zlib::Z_STREAM_END()
MC/DC0%0/2
$res == Compress::Raw::Zlib::Z_OK() or $res == Compress::Raw::Zlib::Z_STREAM_END()
$res == Compress::Raw::Zlib::Z_OK()
$res == Compress::Raw::Zlib::Z_STREAM_END()
Truth table33%1/3
A or B
A= $res == Compress::Raw::Zlib::Z_OK()B= $res == Compress::Raw::Zlib::Z_STREAM_END()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | or $res == Compress::Raw::Zlib::Z_STREAM_END() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | or die "Can't gunzip content: $res"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 28 | $content_ref = \$output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 28 | $content_ref_iscopy++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | elsif ($ce eq 'br') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 12 | require IO::Uncompress::Brotli; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 12 | my $bro = IO::Uncompress::Brotli->create; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 12 | my $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 12 | ▶ | if( defined $content_limit ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 2 | $output = eval { $bro->decompress( $$content_ref, $content_limit ); } | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 10 | $output = eval { $bro->decompress($$content_ref) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 12 | ▶ | $@ and die "Can't unbrotli content: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 10 | $content_ref = \$output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 10 | $content_ref_iscopy++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | ▶ | elsif ($ce eq "x-bzip2" or $ce eq "bzip2") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$ce eq "x-bzip2" or $ce eq "bzip2"
MC/DC100%2/2
$ce eq "x-bzip2" or $ce eq "bzip2"
$ce eq "x-bzip2"
$ce eq "bzip2"
Truth table100%3/3
A or B
A= $ce eq "x-bzip2"B= $ce eq "bzip2"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 28 | require Compress::Raw::Bzip2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 28 | ▶ | if( ! $content_ref_iscopy ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # Create a copy of the input because Bzlib2 will overwrite it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | # :-( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 12 | my $input = "$$content_ref"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 12 | $content_ref = \$input; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 12 | $content_ref_iscopy++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | my ($i, $status) = Compress::Raw::Bunzip2->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 1, # appendInput | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 0, # consumeInput | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0, # small | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 28 | ▶ | $limiter_options{ LimitOutput } || 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$limiter_options{'LimitOutput'} || 0
MC/DC100%1/1
$limiter_options{'LimitOutput'} || 0
$limiter_options{'LimitOutput'}
Truth table100%2/2
A
A= $limiter_options{'LimitOutput'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 28 | my $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | $output = "\0" x $limiter_options{ Bufsize } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 28 | ▶ | if $limiter_options{ Bufsize }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 28 | my $res = $i->bzinflate( $content_ref, \$output ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 28 | ▶ | $res == Compress::Raw::Bzip2::BZ_OUTBUFF_FULL() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | and Carp::croak("Decoded content would be larger than $content_limit octets"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 28 | ▶ | $res == Compress::Raw::Bzip2::BZ_OK() | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$res == Compress::Raw::Bzip2::BZ_OK() or $res == Compress::Raw::Bzip2::BZ_STREAM_END()
MC/DC50%1/2
$res == Compress::Raw::Bzip2::BZ_OK() or $res == Compress::Raw::Bzip2::BZ_STREAM_END()
$res == Compress::Raw::Bzip2::BZ_OK()
$res == Compress::Raw::Bzip2::BZ_STREAM_END()
Truth table66%2/3
A or B
A= $res == Compress::Raw::Bzip2::BZ_OK()B= $res == Compress::Raw::Bzip2::BZ_STREAM_END()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | or $res == Compress::Raw::Bzip2::BZ_STREAM_END() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | or die "Can't bunzip content: $res"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 26 | $content_ref = \$output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 26 | $content_ref_iscopy++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | elsif ($ce eq "deflate") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 6 | require IO::Uncompress::Inflate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 6 | my $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | 6 | my $status = IO::Uncompress::Inflate::inflate($content_ref, \$output, Transparent => 0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 6 | my $error = $IO::Uncompress::Inflate::InflateError; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 6 | ▶ | unless ($status) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | # "Content-Encoding: deflate" is supposed to mean the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | # "zlib" format of RFC 1950, but Microsoft got that | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | # wrong, so some servers sends the raw compressed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | # "deflate" data. This tries to inflate this format. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 2 | $output = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 2 | require IO::Uncompress::RawInflate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 2 | ▶ | unless (IO::Uncompress::RawInflate::rawinflate($content_ref, \$output)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $self->push_header("Client-Warning" => | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | "Could not raw inflate content: $IO::Uncompress::RawInflate::RawInflateError"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | $output = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 6 | ▶ | die "Can't inflate content: $error" unless defined $output; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 6 | $content_ref = \$output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 6 | $content_ref_iscopy++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | ▶ | elsif ($ce eq "compress" || $ce eq "x-compress") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$ce eq "compress" or $ce eq "x-compress"
MC/DC100%2/2
$ce eq "compress" or $ce eq "x-compress"
$ce eq "compress"
$ce eq "x-compress"
Truth table100%3/3
A or B
A= $ce eq "compress"B= $ce eq "x-compress"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 2 | die "Can't uncompress content"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | elsif ($ce eq "base64") { # not really C-T-E, but should be harmless | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 19 | require MIME::Base64; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 19 | $content_ref = \MIME::Base64::decode($$content_ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 19 | $content_ref_iscopy++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | elsif ($ce eq "quoted-printable") { # not really C-T-E, but should be harmless | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 1 | require MIME::QuotedPrint; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 1 | $content_ref = \MIME::QuotedPrint::decode($$content_ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 1 | $content_ref_iscopy++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 3 | die "Don't know how to decode Content-Encoding '$ce'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 107 | ▶ | if ($self->content_is_text || (my $is_xml = $self->content_is_xml)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->content_is_text or my $is_xml = $self->content_is_xml
MC/DC100%2/2
$self->content_is_text or my $is_xml = $self->content_is_xml
$self->content_is_text
my $is_xml = $self->content_is_xml
Truth table100%3/3
A or B
A= $self->content_is_textB= my $is_xml = $self->content_is_xml
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | my $charset = lc( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | $opt{charset} || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | $self->content_type_charset || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | $opt{default_charset} || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 98 | ▶ | $self->content_charset || | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition81%9/11
$opt{'charset'} || $self->content_type_charset || $opt{'default_charset'} || $self->content_charset || 'ISO-8859-1'
$opt{"charset"} or $self->content_type_charset or $opt{"default_charset"} or $self->content_charset
$opt{"charset"} or $self->content_type_charset or $opt{"default_charset"}
$opt{"charset"} or $self->content_type_charset
MC/DC0%0/4
$opt{'charset'} || $self->content_type_charset || $opt{'default_charset'} || $self->content_charset || 'ISO-8859-1'
$opt{"charset"}
$self->content_type_charset
$opt{"default_charset"}
$self->content_charset
Truth table80%4/5
A or B or C or D
A= $opt{"charset"}B= $self->content_type_charsetC= $opt{"default_charset"}D= $self->content_charset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | "ISO-8859-1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 98 | ▶ | if ($charset eq "none") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | # leave it as is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | ▶ | elsif ($charset eq "us-ascii" || $charset eq "iso-8859-1") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$charset eq "us-ascii" or $charset eq "iso-8859-1"
MC/DC100%2/2
$charset eq "us-ascii" or $charset eq "iso-8859-1"
$charset eq "us-ascii"
$charset eq "iso-8859-1"
Truth table100%3/3
A or B
A= $charset eq "us-ascii"B= $charset eq "iso-8859-1"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 14 | ▶ | if ($$content_ref =~ /[^\x00-\x7F]/ && defined &utf8::upgrade) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$$content_ref =~ /[^\x00-\x7F]/ and defined &utf8::upgrade
MC/DC50%1/2
$$content_ref =~ /[^\x00-\x7F]/ and defined &utf8::upgrade
$$content_ref =~ /[^\x00-\x7F]/
defined &utf8::upgrade
Truth table66%2/3
A and B
A= $$content_ref =~ /[^\x00-\x7F]/B= defined &utf8::upgrade
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | 3 | ▶ | unless ($content_ref_iscopy) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 3 | my $copy = $$content_ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 3 | $content_ref = \$copy; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 3 | $content_ref_iscopy++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 3 | utf8::upgrade($$content_ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 27 | require Encode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 27 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | $content_ref = \Encode::decode($charset, $$content_ref, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 27 | ▶ | ($opt{charset_strict} ? Encode::FB_CROAK() : 0) | Encode::LEAVE_SRC()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 27 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 4 | my $retried; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 4 | ▶ | if ($@ =~ /^Unknown encoding/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | 3 | ▶ | my $alt_charset = lc($opt{alt_charset} || ""); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt{'alt_charset'} || ''
MC/DC100%1/1
$opt{'alt_charset'} || ''
$opt{'alt_charset'}
Truth table100%2/2
A
A= $opt{'alt_charset'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 3 | ▶ | if ($alt_charset && $charset ne $alt_charset) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$alt_charset and $charset ne $alt_charset
MC/DC50%1/2
$alt_charset and $charset ne $alt_charset
$alt_charset
$charset ne $alt_charset
Truth table66%2/3
A and B
A= $alt_charsetB= $charset ne $alt_charset
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | # Retry decoding with the alternative charset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | $content_ref = \Encode::decode($alt_charset, $$content_ref, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 2 | ▶ | ($opt{charset_strict} ? Encode::FB_CROAK() : 0) | Encode::LEAVE_SRC()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | unless $alt_charset eq "none"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 2 | $retried++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | 4 | ▶ | die unless $retried; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 25 | ▶ | die "Encode::decode() returned undef improperly" unless defined $$content_ref; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 25 | ▶ | if ($is_xml) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # Get rid of the XML encoding declaration if present | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 10 | $$content_ref =~ s/^\x{FEFF}//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 10 | ▶ | if ($$content_ref =~ /^(\s*<\?xml[^\x00]*?\?>)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 4 | substr($$content_ref, 0, length($1)) =~ s/\sencoding\s*=\s*(["']).*?\1//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | 118 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 13 | ▶ | Carp::croak($@) if $opt{raise_error}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 4 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 105 | ▶ | return $opt{ref} ? $content_ref : $$content_ref; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | sub decodable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | # should match the Content-Encoding values that decoded_content can deal with | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decodable: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 4 | my @enc; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 4 | local $@; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | # XXX preferably we should determine if the modules are available without loading | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # them here | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 4 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 4 | require Compress::Raw::Zlib; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 4 | push(@enc, "gzip", "x-gzip"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 4 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 4 | require IO::Uncompress::Inflate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 4 | require IO::Uncompress::RawInflate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 4 | push(@enc, "deflate"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 4 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 4 | require Compress::Raw::Bzip2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 4 | push(@enc, "x-bzip2", "bzip2"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | 4 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 4 | require IO::Uncompress::Brotli; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 4 | push(@enc, 'br'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # we don't care about announcing the 'identity', 'base64' and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | # 'quoted-printable' stuff | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 4 | ▶ | return wantarray ? @enc : join(", ", @enc); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | sub decode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | 12 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
decode: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 12 | ▶ | return 1 unless $self->header("Content-Encoding"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 11 | ▶ | if (defined(my $content = $self->decoded_content(charset => "none"))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | 10 | $self->remove_header("Content-Encoding", "Content-Length", "Content-MD5"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 10 | $self->content($content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 10 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | sub encode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 13 | ▶ | my($self, @enc) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
encode: called CC=20 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 13 | ▶ | Carp::croak("Can't encode multipart/* messages") if $self->content_type =~ m,^multipart/,; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 12 | ▶ | Carp::croak("Can't encode message/* messages") if $self->content_type =~ m,^message/,; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 11 | ▶ | return 1 unless @enc; # nothing to do | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 10 | my $content = $self->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 10 | for my $encoding (@enc) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 12 | ▶ | if ($encoding eq "identity" || $encoding eq "none") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 7 branches
Condition100%3/3
$encoding eq "identity" or $encoding eq "none"
MC/DC100%2/2
$encoding eq "identity" or $encoding eq "none"
$encoding eq "identity"
$encoding eq "none"
Truth table100%3/3
A or B
A= $encoding eq "identity"B= $encoding eq "none"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | # nothing to do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | elsif ($encoding eq "base64") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 2 | require MIME::Base64; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 2 | $content = MIME::Base64::encode($content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | ▶ | elsif ($encoding eq "gzip" || $encoding eq "x-gzip") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$encoding eq "gzip" or $encoding eq "x-gzip"
MC/DC100%2/2
$encoding eq "gzip" or $encoding eq "x-gzip"
$encoding eq "gzip"
$encoding eq "x-gzip"
Truth table100%3/3
A or B
A= $encoding eq "gzip"B= $encoding eq "x-gzip"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 2 | require IO::Compress::Gzip; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 2 | my $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | 2 | ▶ | IO::Compress::Gzip::gzip(\$content, \$output, Minimal => 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | or die "Can't gzip content: $IO::Compress::Gzip::GzipError"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 2 | $content = $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | elsif ($encoding eq "deflate") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 1 | require IO::Compress::Deflate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 1 | my $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | 1 | ▶ | IO::Compress::Deflate::deflate(\$content, \$output) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | or die "Can't deflate content: $IO::Compress::Deflate::DeflateError"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 1 | $content = $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | ▶ | elsif ($encoding eq "x-bzip2" || $encoding eq "bzip2") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$encoding eq "x-bzip2" or $encoding eq "bzip2"
MC/DC100%2/2
$encoding eq "x-bzip2" or $encoding eq "bzip2"
$encoding eq "x-bzip2"
$encoding eq "bzip2"
Truth table100%3/3
A or B
A= $encoding eq "x-bzip2"B= $encoding eq "bzip2"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 2 | require IO::Compress::Bzip2; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 2 | my $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 2 | ▶ | IO::Compress::Bzip2::bzip2(\$content, \$output) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | or die "Can't bzip2 content: $IO::Compress::Bzip2::Bzip2Error"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 2 | $content = $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | elsif ($encoding eq "br") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 1 | require IO::Compress::Brotli; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 1 | my $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 1 | ▶ | eval { $output = IO::Compress::Brotli::bro($content) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | or die "Can't brotli content: $@"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 1 | $content = $output; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | elsif ($encoding eq "rot13") { # for the fun of it | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 1 | $content =~ tr/A-Za-z/N-ZA-Mn-za-m/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 9 | my $h = $self->header("Content-Encoding"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | 9 | ▶ | unshift(@enc, $h) if $h; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | 9 | $self->header("Content-Encoding", join(", ", @enc)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 9 | $self->remove_header("Content-Length", "Content-MD5"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 9 | $self->content($content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | 9 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | sub as_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 90 | ▶ | my($self, $eol) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_string: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 90 | ▶ | $eol = "\n" unless defined $eol; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | # The calculation of content might update the headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | # so we need to do that first. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 90 | my $content = $self->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | 90 | ▶ | return join("", $self->{'_headers'}->as_string($eol), | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@_ == 1 and length $content and not $content =~ /\n\z/
@_ == 1 and length $content
MC/DC100%3/3
@_ == 1 and length $content and not $content =~ /\n\z/
@_ == 1
length $content
not $content =~ /\n\z/
Truth table100%4/4
A and B and not(C)
A= @_ == 1B= length $contentC= not $content =~ /\n\z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | $eol, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | $content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | (@_ == 1 && length($content) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | $content !~ /\n\z/) ? "\n" : "", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | sub dump | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 15 | ▶ | my($self, %opt) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dump: called CC=12 SCAR=24.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 15 | my $content = $self->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | 15 | my $chopped = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 15 | ▶ | if (!ref($content)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 15 | my $maxlen = $opt{maxlength}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 15 | ▶ | $maxlen = 512 unless defined($maxlen); | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 15 | ▶ | if ($maxlen && length($content) > $maxlen * 1.1 + 3) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$maxlen and length $content > $maxlen * "1.1" + 3
MC/DC100%2/2
$maxlen and length $content > $maxlen * "1.1" + 3
$maxlen
length $content > $maxlen * "1.1" + 3
Truth table100%3/3
A and B
A= $maxlenB= length $content > $maxlen * "1.1" + 3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | 1 | $chopped = length($content) - $maxlen; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | 1 | $content = substr($content, 0, $maxlen) . "..."; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 15 | $content =~ s/\\/\\\\/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | 15 | $content =~ s/\t/\\t/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 15 | $content =~ s/\r/\\r/g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | # no need for 3 digits in escape for these | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 15 | $content =~ s/([\0-\11\13-\037])(?!\d)/sprintf('\\%o',ord($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 15 | $content =~ s/([\0-\11\13-\037\177-\377])/sprintf('\\x%02X',ord($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 15 | $content =~ s/([^\12\040-\176])/sprintf('\\x{%X}',ord($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | # remaining whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 15 | $content =~ s/( +)\n/("\\40" x length($1)) . "\n"/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | 15 | $content =~ s/(\n+)\n/("\\n" x length($1)) . "\n"/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | 15 | $content =~ s/\n\z/\\n/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 15 | my $no_content = $opt{no_content}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | 15 | ▶ | $no_content = "(no content)" unless defined $no_content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 15 | ▶ | if ($content eq $no_content) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | # escape our $no_content marker | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 2 | $content =~ s/^(.)/sprintf('\\x%02X',ord($1))/eg; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | elsif ($content eq "") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 8 | $content = $no_content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | 15 | my @dump; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 15 | ▶ | push(@dump, $opt{preheader}) if $opt{preheader}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 15 | push(@dump, $self->{_headers}->as_string, $content); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 15 | ▶ | push(@dump, "(+ $chopped more bytes not shown)") if $chopped; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 15 | my $dump = join("\n", @dump, ""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 15 | ▶ | $dump =~ s/^/$opt{prefix}/gm if $opt{prefix}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 15 | ▶ | print $dump unless defined wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | 15 | return $dump; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | # allow subclasses to override what will handle individual parts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | sub _part_class { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 9 | ▶ | return __PACKAGE__; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_part_class: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | sub parts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 27 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parts: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | 27 | ▶ | if (defined(wantarray) && (!exists $self->{_parts} || ref($self->{_content}) eq "SCALAR")) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined wantarray and !exists $self->{"_parts"} || ref $self->{"_content"} eq "SCALAR"
not exists $self->{"_parts"} or ref $self->{"_content"} eq "SCALAR"
MC/DC66%2/3
defined wantarray and !exists $self->{"_parts"} || ref $self->{"_content"} eq "SCALAR"
defined wantarray
not exists $self->{"_parts"}
ref $self->{"_content"} eq "SCALAR"
Truth table75%3/4
A and not(B) or C
A= defined wantarrayB= not exists $self->{"_parts"}C= ref $self->{"_content"} eq "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 13 | $self->_parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | 27 | my $old = $self->{_parts}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | 27 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 8 | ▶ | my @parts = map { ref($_) eq 'ARRAY' ? @$_ : $_ } @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | 8 | ▶ | my $ct = $self->content_type || ""; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->content_type || ''
MC/DC100%1/1
$self->content_type || ''
$self->content_type
Truth table100%2/2
A
A= $self->content_type
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | 8 | ▶ | if ($ct =~ m,^message/,) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 3 | ▶ | Carp::croak("Only one part allowed for $ct content") | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | if @parts > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | elsif ($ct !~ m,^multipart/,) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | 3 | $self->remove_content_headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | 3 | $self->content_type("multipart/mixed"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 7 | $self->{_parts} = \@parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 7 | _stale_content($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 26 | ▶ | return @$old if wantarray; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | 11 | return $old->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | sub add_part { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | 4 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_part: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 4 | ▶ | if (($self->content_type || "") !~ m,^multipart/,) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%2/2
$self->content_type || ''
MC/DC100%1/1
$self->content_type || ''
$self->content_type
Truth table100%2/2
A
A= $self->content_type
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | 2 | my $p = $self->_part_class->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | $self->remove_content_headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | $self->content(""), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | 2 | $self->content_type("multipart/mixed"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 2 | $self->{_parts} = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | 2 | ▶ | if ($p->headers->header_field_names || $p->content ne "") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$p->headers->header_field_names or $p->content ne ""
MC/DC50%1/2
$p->headers->header_field_names or $p->content ne ""
$p->headers->header_field_names
$p->content ne ""
Truth table66%2/3
A or B
A= $p->headers->header_field_namesB= $p->content ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | 1 | push(@{$self->{_parts}}, $p); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | ▶ | elsif (!exists $self->{_parts} || ref($self->{_content}) eq "SCALAR") { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
not exists $self->{"_parts"} or ref $self->{"_content"} eq "SCALAR"
MC/DC50%1/2
not exists $self->{"_parts"} or ref $self->{"_content"} eq "SCALAR"
not exists $self->{"_parts"}
ref $self->{"_content"} eq "SCALAR"
Truth table66%2/3
not(A) or B
A= not exists $self->{"_parts"}B= ref $self->{"_content"} eq "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | 1 | $self->_parts; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | 4 | push(@{$self->{_parts}}, @_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | 4 | _stale_content($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | 4 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | sub _stale_content { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | 11 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stale_content: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 11 | ▶ | if (ref($self->{_content}) eq "SCALAR") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | # must recalculate now | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | 1 | $self->_content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | # just invalidate cache | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | 10 | delete $self->{_content}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 10 | delete $self->{_content_ref}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | # delegate all other method calls to the headers object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | 17 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | 73 | ▶ | my ( $package, $method ) = $AUTOLOAD =~ m/\A(.+)::([^:]*)\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 73 | my $code = $_[0]->can($method); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | 73 | ▶ | Carp::croak( | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | qq(Can't locate object method "$method" via package "$package")) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | unless $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | 70 | goto &$code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | sub can { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | 125 | ▶ | my ( $self, $method ) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | 125 | ▶ | if ( my $own_method = $self->SUPER::can($method) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | 20 | return $own_method; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | 105 | ▶ | my $headers = ref($self) ? $self->headers : 'HTTP::Headers'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 105 | ▶ | if ( $headers->can($method) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | # We create the function here so that it will not need to be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | # autoloaded or recreated the next time. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | 17 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | *$method = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | 1003 | ▶ | local $Carp::Internal{ +__PACKAGE__ } = 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | 1003 | shift->headers->$method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | 72 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 72 | return \&$method; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | 33 | return undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | ▶ | sub DESTROY { } # avoid AUTOLOADing it | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | # Private method to access members in %$self | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | sub _elem | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | 394 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_elem: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | 394 | my $elem = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | 394 | my $old = $self->{$elem}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | 394 | ▶ | $self->{$elem} = $_[0] if @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | 394 | return $old; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | # Create private _parts attribute from current _content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | sub _parts { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parts: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | 14 | my $ct = $self->content_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | 14 | ▶ | if ($ct =~ m,^multipart/,) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 4 | require HTTP::Headers::Util; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | 4 | my @h = HTTP::Headers::Util::split_header_words($self->header("Content-Type")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | 4 | ▶ | die "Assert" unless @h; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | 4 | my %h = @{$h[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | 4 | ▶ | if (defined(my $b = $h{boundary})) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | 3 | my $str = $self->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 3 | $str =~ s/\r?\n--\Q$b\E--.*//s; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | 3 | ▶ | if ($str =~ s/(^|.*?\r?\n)--\Q$b\E\r?\n//s) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 3 | $self->{_parts} = [map $self->_part_class->parse($_), | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | split(/\r?\n--\Q$b\E\r?\n/, $str)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | elsif ($ct eq "message/http") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | 4 | require HTTP::Request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 4 | require HTTP::Response; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | 4 | my $content = $self->content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | 4 | ▶ | my $class = ($content =~ m,^(HTTP/.*)\n,) ? | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | "HTTP::Response" : "HTTP::Request"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | 4 | $self->{_parts} = [$class->parse($content)]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | elsif ($ct =~ m,^message/,) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 2 | $self->{_parts} = [ $self->_part_class->parse($self->content) ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | 14 | ▶ | $self->{_parts} ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"_parts"} ||= []
MC/DC100%1/1
$self->{"_parts"} ||= []
$self->{"_parts"}
Truth table100%2/2
A
A= $self->{"_parts"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | # Create private _content attribute from current _parts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | sub _content { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | 10 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_content: called CC=10 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 10 | ▶ | my $ct = $self->{_headers}->header("Content-Type") || "multipart/mixed"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'_headers'}->header('Content-Type') || 'multipart/mixed'
MC/DC0%0/1
$self->{'_headers'}->header('Content-Type') || 'multipart/mixed'
$self->{'_headers'}->header('Content-Type')
Truth table50%1/2
A
A= $self->{'_headers'}->header('Content-Type')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | 10 | ▶ | if ($ct =~ m,^\s*message/,i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | 2 | _set_content($self, $self->{_parts}[0]->as_string($CRLF), 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 8 | require HTTP::Headers::Util; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | 8 | my @v = HTTP::Headers::Util::split_header_words($ct); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | 8 | ▶ | Carp::carp("Multiple Content-Type headers") if @v > 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | 8 | @v = @{$v[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | 8 | my $boundary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | my $boundary_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 8 | ▶ | for (my @tmp = @v; @tmp;) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | 10 | my($k, $v) = splice(@tmp, 0, 2); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | 10 | ▶ | if ($k eq "boundary") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 2 | $boundary = $v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | 2 | $boundary_index = @v - @tmp - 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | 2 | last; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | 8 | my @parts = map $_->as_string($CRLF), @{$self->{_parts}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 8 | my $bno = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | 8 | ▶ | $boundary = _boundary() unless defined $boundary; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | CHECK_BOUNDARY: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | 8 | for (@parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 15 | ▶ | if (index($_, $boundary) >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | # must have a better boundary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | 1 | $boundary = _boundary(++$bno); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | 1 | redo CHECK_BOUNDARY; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | 8 | ▶ | if ($boundary_index) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | 2 | $v[$boundary_index] = $boundary; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | 6 | push(@v, boundary => $boundary); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 8 | $ct = HTTP::Headers::Util::join_header_words(@v); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | 8 | $self->{_headers}->header("Content-Type", $ct); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | 8 | _set_content($self, "--$boundary$CRLF" . | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | join("$CRLF--$boundary$CRLF", @parts) . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | "$CRLF--$boundary--$CRLF", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | sub _boundary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 7 | ▶ | my $size = shift || return "xYzZY"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_boundary: called CC=2 SCAR=6.9
Condition100%2/2
shift() || (return 'xYzZY')
MC/DC100%1/1
shift() || (return 'xYzZY')
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | 1 | require MIME::Base64; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | 1 | my $b = MIME::Base64::encode(join("", map chr(rand(256)), 1..$size*3), ""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | 1 | $b =~ s/[\W]/X/g; # ensure alnum only | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 1 | $b; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | 17 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | =pod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | =encoding UTF-8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | HTTP::Message - HTTP style message (base class) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | version 7.02 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | use parent 'HTTP::Message'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | An C<HTTP::Message> object contains some headers and a content body. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | The following methods are available: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | =item $mess = HTTP::Message->new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | =item $mess = HTTP::Message->new( $headers ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | =item $mess = HTTP::Message->new( $headers, $content ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | This constructs a new message object. Normally you would want | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | construct C<HTTP::Request> or C<HTTP::Response> objects instead. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | The optional $header argument should be a reference to an | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | C<HTTP::Headers> object or a plain array reference of key/value pairs. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | If an C<HTTP::Headers> object is provided then a copy of it will be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | embedded into the constructed message, i.e. it will not be owned and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | can be modified afterwards without affecting the message. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | The optional $content argument should be a string of bytes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | =item $mess = HTTP::Message->parse( $str ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | This constructs a new message object by parsing the given string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | =item $mess->headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | Returns the embedded C<HTTP::Headers> object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | =item $mess->headers_as_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | =item $mess->headers_as_string( $eol ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | Call the as_string() method for the headers in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | message. This will be the same as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | $mess->headers->as_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | but it will make your program a whole character shorter :-) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | =item $mess->content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | =item $mess->content( $bytes ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | The content() method sets the raw content if an argument is given. If no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | argument is given the content is not touched. In either case the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | original raw content is returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | If the C<undef> argument is given, the content is reset to its default value, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | which is an empty string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | Note that the content should be a string of bytes. Strings in perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | can contain characters outside the range of a byte. The C<Encode> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | module can be used to turn such strings into a string of bytes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | =item $mess->add_content( $bytes ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | The add_content() methods appends more data bytes to the end of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | current content buffer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 955 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 956 | =item $mess->add_content_utf8( $string ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 958 | The add_content_utf8() method appends the UTF-8 bytes representing the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 959 | string to the end of the current content buffer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 960 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 961 | =item $mess->content_ref | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 962 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 963 | =item $mess->content_ref( \$bytes ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 965 | The content_ref() method will return a reference to content buffer string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 966 | It can be more efficient to access the content this way if the content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 967 | is huge, and it can even be used for direct manipulation of the content, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 968 | for instance: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 969 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 970 | ${$res->content_ref} =~ s/\bfoo\b/bar/g; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 972 | This example would modify the content buffer in-place. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 973 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 974 | If an argument is passed it will setup the content to reference some | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 975 | external source. The content() and add_content() methods | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 976 | will automatically dereference scalar references passed this way. For | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 977 | other references content() will return the reference itself and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 978 | add_content() will refuse to do anything. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 979 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 980 | =item $mess->content_charset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 982 | This returns the charset used by the content in the message. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 983 | charset is either found as the charset attribute of the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 984 | C<Content-Type> header or by guessing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 985 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 986 | See L<http://www.w3.org/TR/REC-html40/charset.html#spec-char-encoding> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 987 | for details about how charset is determined. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 988 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 989 | =item $mess->decoded_content( %options ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 990 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 991 | Returns the content with any C<Content-Encoding> undone and, for textual content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 992 | (C<Content-Type> values starting with C<text/>, exactly matching | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 993 | C<application/xml>, or ending with C<+xml>), the raw content's character set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 994 | decoded into Perl's Unicode string format. Note that this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 995 | L<does not currently|https://github.com/libwww-perl/HTTP-Message/pull/99> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 996 | attempt to decode declared character sets for any other content types like | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 997 | C<application/json> or C<application/javascript>. If the C<Content-Encoding> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 998 | or C<charset> of the message is unknown, this method will fail by returning | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 999 | C<undef>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1000 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1001 | The following options can be specified. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1002 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1003 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1005 | =item C<charset> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1006 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1007 | This overrides the charset parameter for text content. The value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1008 | C<none> can used to suppress decoding of the charset. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1009 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1010 | =item C<default_charset> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1011 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1012 | This overrides the default charset guessed by content_charset() or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1013 | if that fails "ISO-8859-1". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1014 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1015 | =item C<alt_charset> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1016 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1017 | If decoding fails because the charset specified in the Content-Type header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1018 | isn't recognized by Perl's Encode module, then try decoding using this charset | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1019 | instead of failing. The C<alt_charset> might be specified as C<none> to simply | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1020 | return the string without any decoding of charset as alternative. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1021 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1022 | =item C<charset_strict> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1023 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1024 | Abort decoding if malformed characters is found in the content. By | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1025 | default you get the substitution character ("\x{FFFD}") in place of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1026 | malformed characters. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1027 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1028 | =item C<raise_error> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1029 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1030 | If TRUE then raise an exception if not able to decode content. Reason | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1031 | might be that the specified C<Content-Encoding> or C<charset> is not | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1032 | supported. If this option is FALSE, then decoded_content() will return | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1033 | C<undef> on errors, but will still set $@. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1035 | =item C<ref> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1036 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1037 | If TRUE then a reference to decoded content is returned. This might | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1038 | be more efficient in cases where the decoded content is identical to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1039 | the raw content as no data copying is required in this case. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1040 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1041 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1042 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1043 | =item $mess->decodable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1044 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1045 | =item HTTP::Message::decodable() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1046 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1047 | This returns the encoding identifiers that decoded_content() can | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1048 | process. In scalar context returns a comma separated string of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1049 | identifiers. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1050 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1051 | This value is suitable for initializing the C<Accept-Encoding> request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1052 | header field. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1053 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1054 | =item $mess->decode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1055 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1056 | This method tries to replace the content of the message with the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1057 | decoded version and removes the C<Content-Encoding> header. Returns | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1058 | TRUE if successful and FALSE if not. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1059 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1060 | If the message does not have a C<Content-Encoding> header this method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1061 | does nothing and returns TRUE. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1062 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1063 | Note that the content of the message is still bytes after this method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1064 | has been called and you still need to call decoded_content() if you | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1065 | want to process its content as a string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1066 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1067 | =item $mess->encode( $encoding, ... ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1068 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1069 | Apply the given encodings to the content of the message. Returns TRUE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1070 | if successful. The "identity" (non-)encoding is always supported; other | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1071 | currently supported encodings, subject to availability of required | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1072 | additional modules, are "gzip", "deflate", "x-bzip2", "base64" and "br". | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1073 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1074 | A successful call to this function will set the C<Content-Encoding> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1075 | header. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1077 | Note that C<multipart/*> or C<message/*> messages can't be encoded and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1078 | this method will croak if you try. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1079 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1080 | =item $mess->parts | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1081 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1082 | =item $mess->parts( @parts ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1083 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1084 | =item $mess->parts( \@parts ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1085 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1086 | Messages can be composite, i.e. contain other messages. The composite | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1087 | messages have a content type of C<multipart/*> or C<message/*>. This | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1088 | method give access to the contained messages. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1090 | The argumentless form will return a list of C<HTTP::Message> objects. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1091 | If the content type of $msg is not C<multipart/*> or C<message/*> then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1092 | this will return the empty list. In scalar context only the first | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1093 | object is returned. The returned message parts should be regarded as | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1094 | read-only (future versions of this library might make it possible | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1095 | to modify the parent by modifying the parts). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1096 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1097 | If the content type of $msg is C<message/*> then there will only be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1098 | one part returned. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1099 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1100 | If the content type is C<message/http>, then the return value will be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1101 | either an C<HTTP::Request> or an C<HTTP::Response> object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1103 | If a @parts argument is given, then the content of the message will be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1104 | modified. The array reference form is provided so that an empty list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1105 | can be provided. The @parts array should contain C<HTTP::Message> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1106 | objects. The @parts objects are owned by $mess after this call and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1107 | should not be modified or made part of other messages. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1109 | When updating the message with this method and the old content type of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1110 | $mess is not C<multipart/*> or C<message/*>, then the content type is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1111 | set to C<multipart/mixed> and all other content headers are cleared. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1113 | This method will croak if the content type is C<message/*> and more | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1114 | than one part is provided. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1116 | =item $mess->add_part( $part ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1118 | This will add a part to a message. The $part argument should be | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1119 | another C<HTTP::Message> object. If the previous content type of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1120 | $mess is not C<multipart/*> then the old content (together with all | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1121 | content headers) will be made part #1 and the content type made | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1122 | C<multipart/mixed> before the new part is added. The $part object is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1123 | owned by $mess after this call and should not be modified or made part | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1124 | of other messages. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1126 | There is no return value. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1127 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1128 | =item $mess->clear | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1130 | Will clear the headers and set the content to the empty string. There | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1131 | is no return value | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1133 | =item $mess->protocol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1135 | =item $mess->protocol( $proto ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1136 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1137 | Sets the HTTP protocol used for the message. The protocol() is a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1138 | like C<HTTP/1.0> or C<HTTP/1.1>. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1140 | =item $mess->clone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1142 | Returns a copy of the message object. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1144 | =item $mess->as_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1146 | =item $mess->as_string( $eol ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1148 | Returns the message formatted as a single string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1150 | The optional $eol parameter specifies the line ending sequence to use. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1151 | The default is "\n". If no $eol is given then as_string will ensure | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1152 | that the returned string is newline terminated (even when the message | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1153 | content is not). No extra newline is appended if an explicit $eol is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1154 | passed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1156 | =item $mess->dump( %opt ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1158 | Returns the message formatted as a string. In void context print the string. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1159 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1160 | This differs from C<< $mess->as_string >> in that it escapes the bytes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1161 | of the content so that it's safe to print them and it limits how much | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1162 | content to print. The escapes syntax used is the same as for Perl's | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1163 | double quoted strings. If there is no content the string "(no | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1164 | content)" is shown in its place. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1165 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1166 | Options to influence the output can be passed as key/value pairs. The | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1167 | following options are recognized: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1169 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1171 | =item maxlength => $num | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1173 | How much of the content to show. The default is 512. Set this to 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1174 | for unlimited. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1176 | If the content is longer then the string is chopped at the limit and | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1177 | the string "...\n(### more bytes not shown)" appended. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1179 | =item no_content => $str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1181 | Replaces the "(no content)" marker. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1182 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1183 | =item prefix => $str | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1185 | A string that will be prefixed to each line of the dump. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1186 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1187 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1189 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1191 | All methods unknown to C<HTTP::Message> itself are delegated to the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1192 | C<HTTP::Headers> object that is part of every message. This allows | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1193 | convenient access to these methods. Refer to L<HTTP::Headers> for | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1194 | details of these methods: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1195 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1196 | $mess->header( $field => $val ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1197 | $mess->push_header( $field => $val ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1198 | $mess->init_header( $field => $val ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1199 | $mess->remove_header( $field ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1200 | $mess->remove_content_headers | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1201 | $mess->header_field_names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1202 | $mess->scan( \&doit ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1203 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1204 | $mess->date | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1205 | $mess->expires | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1206 | $mess->if_modified_since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1207 | $mess->if_unmodified_since | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1208 | $mess->last_modified | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1209 | $mess->content_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1210 | $mess->content_encoding | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1211 | $mess->content_length | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1212 | $mess->content_language | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1213 | $mess->title | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1214 | $mess->user_agent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1215 | $mess->server | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1216 | $mess->from | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1217 | $mess->referer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1218 | $mess->www_authenticate | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1219 | $mess->authorization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1220 | $mess->proxy_authorization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1221 | $mess->authorization_basic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1222 | $mess->proxy_authorization_basic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1224 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1225 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1226 | Gisle Aas <gisle@activestate.com> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1227 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1228 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1229 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1230 | This software is copyright (c) 1994 by Gisle Aas. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1232 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1233 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1235 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1236 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 1237 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||