| 1 | package LWP::Protocol::UWSGI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use version; our $VERSION = qv('v1.1.6'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use HTTP::Response qw( ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use LWP::Protocol::http qw( ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Encode; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use URI::Escape::XS qw(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use base qw/LWP::Protocol::http/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 1 | LWP::Protocol::implementor($_, __PACKAGE__) for qw( uwsgi ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | our $CRLF = $LWP::Protocol::http::CRLF; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | LWP::Protocol::UWSGI - uwsgi support for LWP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | use LWP::Protocol::UWSGI; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | use LWP::UserAgent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | $res = $ua->get("uwsgi://www.example.com"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | The LWP::Protocol::UWSGI module provide support for using uwsgi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | protocol with LWP. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | This module unbundled with the libwww-perl. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | L<LWP::UserAgent>, L<LWP::Protocol> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | =head1 COPYRIGHT | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | Copyright 2015 Nikolas Shulyakovskiy. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | This library is free software; you can redistribute it and/or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | sub request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my($self, $request, $proxy, $arg, $size, $timeout) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
request: not called CC=87 SCAR=89.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $size ||= 4096; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$size ||= 4096
MC/DC0%0/1
$size ||= 4096
$size
Truth table0%0/2
A
A= $size
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | # check method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $method = $request->method; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | unless ($method =~ /^[A-Za-z0-9_!\#\$%&\'*+\-.^\`|~]+$/) { # HTTP token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | return HTTP::Response->new( &HTTP::Status::RC_BAD_REQUEST, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 'Library does not allow method ' . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | "$method for 'uwsgi:' URLs"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | my $url = $request->uri; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | unless($$url =~ m,^uwsgi://([^/?\#:]+)(?:\:(\d+))/,){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | return HTTP::Response->new( &HTTP::Status::RC_BAD_REQUEST, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 'Library does not allow this host ' . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | "$$url for 'uwsgi:' URLs"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | my ($host,$port) = $proxy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ? ($proxy->host,$proxy->port) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | : ($1,$2); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | my $fullpath = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | $method eq 'CONNECT' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | ? $url->host . ":" . $url->port | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | : $proxy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ? $url->as_string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | : do { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | my $path = $url->path_query; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $path = "/$path" if $path !~m{^/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | $path | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | my $socket; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $conn_cache = $self->{ua}{conn_cache}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $cache_key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( $conn_cache ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $cache_key = "$host:$port"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if ( $socket = $conn_cache->withdraw($self->socket_type,$cache_key)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if ($socket->can_read(0)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # if the socket is readable, then either the peer has closed the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # connection or there are some garbage bytes on it. In either | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | # case we abandon it. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $socket->close; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | $socket = undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } # else use $socket | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ( ! $socket ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # connect to remote site w/o reusing established socket | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $socket = $self->_new_socket($host, $port, $timeout ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $self->_check_sock($request, $socket); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my %h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $request_headers = $request->headers->clone; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | $self->_fixup_header($request_headers, $url, $proxy); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | $request_headers->scan(sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | my($k, $v) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $k =~ s/^://; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $v =~ s/\n/ /g; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $h{$k}=$v; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $content_ref = $request->content_ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | $content_ref = $$content_ref if ref($$content_ref); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $chunked; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | my $has_content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if (ref($content_ref) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $clen = $request_headers->header('Content-Length'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | ▶ | $has_content++ if $clen; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | unless (defined $clen) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $h{"Transfer-Encoding"} = "chunked"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $has_content++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $chunked++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # Set (or override) Content-Length header | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my $clen = $request_headers->header('Content-Length'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | if (defined($$content_ref) && length($$content_ref)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/3
defined $$content_ref and length $$content_ref
MC/DC0%0/2
defined $$content_ref and length $$content_ref
defined $$content_ref
length $$content_ref
Truth table0%0/3
A and B
A= defined $$content_refB= length $$content_ref
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $has_content = length($$content_ref); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | if (!defined($clen) || $clen ne $has_content) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $clen or $clen ne $has_content
MC/DC0%0/2
not defined $clen or $clen ne $has_content
not defined $clen
$clen ne $has_content
Truth table0%0/3
not(A) or B
A= not defined $clenB= $clen ne $has_content
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | if (defined $clen) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | warn "Content-Length header value was wrong, fixed"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | delete $h{'Content-Length'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $h{'Content-Length'} = $has_content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | elsif ($clen) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | warn "Content-Length set when there is no content, fixed"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | delete $h{'Content-Length'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $env = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | $env->{QUERY_STRING} = $fullpath =~ m,^[^?]+\?(.+)$, ? $1 : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $env->{REQUEST_METHOD} = $method; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | $env->{CONTENT_LENGTH} = defined $request_headers->header('Content-Length') ? $request_headers->header('Content-Length') : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $env->{CONTENT_TYPE} = $method =~ /post/i ? 'application/x-www-form-urlencoded' : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | $env->{REQUEST_URI} = $fullpath; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | $env->{PATH_INFO} = $url->path; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | $env->{SERVER_PROTOCOL}= 'HTTP/1.1'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | $env->{REMOTE_ADDR} = $socket->sockhost; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $env->{REMOTE_PORT} = $socket->sockport; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $env->{SERVER_PORT} = $port; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $env->{SERVER_NAME} = $host; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | if ($request->header('X-UWSGI-Nginx-Compatible-Mode')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | $env->{PATH_INFO} = URI::Escape::XS::uri_unescape( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | $env->{PATH_INFO} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | foreach my $k (keys %h) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | (my $env_k = uc $k) =~ tr/-/_/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | $env->{"HTTP_$env_k"} = defined $h{$k} ? $h{$k} : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my $data = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | foreach my $k (sort keys %$env) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | die "Undef value found for $k" unless defined $env->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $data .= pack 'v/a*v/a*', map { Encode::encode('utf8', $_) } $k, $env->{$k}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $req_buf = pack('C1v1C1', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 5, # PSGI_MODIFIER1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | length($data), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0, # PSGI_MODIFIER2, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ) . $data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | ▶ | if (!$has_content || $has_content > 8*1024) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $has_content or $has_content > 8192
MC/DC0%0/2
not $has_content or $has_content > 8192
not $has_content
$has_content > 8192
Truth table0%0/3
not(A) or B
A= not $has_contentB= $has_content > 8192
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | WRITE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # Since this just writes out the header block it should almost | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # always succeed to send the whole buffer in a single write call. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my $n = $socket->syswrite($req_buf, length($req_buf)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | ▶ | unless (defined $n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | redo WRITE if $!{EINTR}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ($!{EWOULDBLOCK} || $!{EAGAIN}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$!{"EWOULDBLOCK"} or $!{"EAGAIN"}
MC/DC0%0/2
$!{"EWOULDBLOCK"} or $!{"EAGAIN"}
$!{"EWOULDBLOCK"}
$!{"EAGAIN"}
Truth table0%0/3
A or B
A= $!{"EWOULDBLOCK"}B= $!{"EAGAIN"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | select(undef, undef, undef, 0.1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | redo WRITE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | die "write failed: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if ($n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | substr($req_buf, 0, $n, ""); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | select(undef, undef, undef, 0.5); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | ▶ | redo WRITE if length $req_buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | my($code, $mess, @junk); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | my $drop_connection; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if ($has_content) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my $eof; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | my $wbuf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $woffset = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | INITIAL_READ: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if (ref($content_ref) eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my $buf = &$content_ref(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | $buf = "" unless defined($buf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | ▶ | $buf = sprintf "%x%s%s%s", length($buf), $CRLF, $buf, $CRLF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | if $chunked; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | substr($buf, 0, 0) = $req_buf if $req_buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $wbuf = \$buf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if ($req_buf) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | my $buf = $req_buf . $$content_ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | $wbuf = \$buf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | $wbuf = $content_ref; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | $eof = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | my $fbits = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | vec($fbits, fileno($socket), 1) = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | WRITE: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | ▶ | while ($woffset < length($$wbuf)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my $sel_timeout = $timeout; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my $time_before; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | $time_before = time if $sel_timeout; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my $rbits = $fbits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 0 | my $wbits = $fbits; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | my $sel_timeout_before = $sel_timeout; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | SELECT: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | my $nfound = select($rbits, $wbits, undef, $sel_timeout); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | ▶ | if ($nfound < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if ($!{EINTR} || $!{EWOULDBLOCK} || $!{EAGAIN}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
$!{"EINTR"} or $!{"EWOULDBLOCK"}
MC/DC0%0/3
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
$!{"EINTR"}
$!{"EWOULDBLOCK"}
$!{"EAGAIN"}
Truth table0%0/4
A or B or C
A= $!{"EINTR"}B= $!{"EWOULDBLOCK"}C= $!{"EAGAIN"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | if ($time_before) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $sel_timeout = $sel_timeout_before - (time - $time_before); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | $sel_timeout = 0 if $sel_timeout < 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | redo SELECT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | die "select failed: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | if (defined($rbits) && $rbits =~ /[^\0]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $rbits and $rbits =~ /[^\0]/
MC/DC0%0/2
defined $rbits and $rbits =~ /[^\0]/
defined $rbits
$rbits =~ /[^\0]/
Truth table0%0/3
A and B
A= defined $rbitsB= $rbits =~ /[^\0]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | # readable | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $buf = $socket->_rbuf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my $n = $socket->sysread($buf, 1024, length($buf)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | unless (defined $n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | die "read failed: $!" unless $!{EINTR} || $!{EWOULDBLOCK} || $!{EAGAIN}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
$!{"EINTR"} or $!{"EWOULDBLOCK"}
MC/DC0%0/3
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
$!{"EINTR"}
$!{"EWOULDBLOCK"}
$!{"EAGAIN"}
Truth table0%0/4
A or B or C
A= $!{"EINTR"}B= $!{"EWOULDBLOCK"}C= $!{"EAGAIN"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | # if we get here the rest of the block will do nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | # and we will retry the read on the next round | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | elsif ($n == 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | # the server closed the connection before we finished | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | # writing all the request content. No need to write any more. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | $drop_connection++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | last WRITE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | $socket->_rbuf($buf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my @h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | ▶ | if (!$code && $buf =~ /\015?\012\015?\012/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $code and $buf =~ /\015?\012\015?\012/
MC/DC0%0/2
not $code and $buf =~ /\015?\012\015?\012/
not $code
$buf =~ /\015?\012\015?\012/
Truth table0%0/3
not(A) and B
A= not $codeB= $buf =~ /\015?\012\015?\012/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | # a whole response header is present, so we can read it without blocking | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ($code, $mess, @h) = $socket->read_response_headers( laxed => 1, junk_out => \@junk ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if ($code eq "100") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | undef($code); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | goto INITIAL_READ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | $drop_connection++; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | last WRITE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | # XXX should perhaps try to abort write in a nice way too | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if (defined($wbits) && $wbits =~ /[^\0]/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $wbits and $wbits =~ /[^\0]/
MC/DC0%0/2
defined $wbits and $wbits =~ /[^\0]/
defined $wbits
$wbits =~ /[^\0]/
Truth table0%0/3
A and B
A= defined $wbitsB= $wbits =~ /[^\0]/
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | my $n = $socket->syswrite($$wbuf, length($$wbuf), $woffset); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | ▶ | unless (defined $n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | ▶ | die "write failed: $!" unless $!{EINTR} || $!{EWOULDBLOCK} || $!{EAGAIN}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
$!{"EINTR"} or $!{"EWOULDBLOCK"}
MC/DC0%0/3
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
$!{"EINTR"}
$!{"EWOULDBLOCK"}
$!{"EAGAIN"}
Truth table0%0/4
A or B or C
A= $!{"EINTR"}B= $!{"EWOULDBLOCK"}C= $!{"EAGAIN"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $n = 0; # will retry write on the next round | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 0 | elsif ($n == 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | die "write failed: no bytes written"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $woffset += $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | if (!$eof && $woffset >= length($$wbuf)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $eof and $woffset >= length $$wbuf
MC/DC0%0/2
not $eof and $woffset >= length $$wbuf
not $eof
$woffset >= length $$wbuf
Truth table0%0/3
not(A) and B
A= not $eofB= $woffset >= length $$wbuf
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # need to refill buffer from $content_ref code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $buf = &$content_ref(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | ▶ | $buf = "" unless defined($buf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | $eof++ unless length($buf); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | ▶ | $buf = sprintf "%x%s%s%s", length($buf), $CRLF, $buf, $CRLF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | if $chunked; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $wbuf = \$buf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | $woffset = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } # WRITE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my @h; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | ▶ | ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, junk_out => \@junk) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | unless $code; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | ▶ | ($code, $mess, @h) = $socket->read_response_headers(laxed => 1, junk_out => \@junk) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | if $code eq "100"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | my $response = HTTP::Response->new($code, $mess); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my $peer_http_version = $socket->peer_http_version; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $response->protocol("HTTP/$peer_http_version"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | local $HTTP::Headers::TRANSLATE_UNDERSCORE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | $response->push_header(@h); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ▶ | $response->push_header("Client-Junk" => \@junk) if @junk; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | $response->request($request); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | $self->_get_sock_info($response, $socket); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | if ($method eq "CONNECT") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | $response->{client_socket} = $socket; # so it can be picked up | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | return $response; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | ▶ | if (my @te = $response->remove_header('Transfer-Encoding')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | $response->push_header('Client-Transfer-Encoding', \@te); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | $response->push_header('Client-Response-Num', scalar $socket->increment_response_count); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 0 | my $complete; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | $response = $self->collect($arg, $response, sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | my $buf = ""; #prevent use of uninitialized value in SSLeay.xs | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my $n; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | READ: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | $n = $socket->read_entity_body($buf, $size); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | unless (defined $n) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | ▶ | redo READ if $!{EINTR} || $!{EWOULDBLOCK} || $!{EAGAIN} || $!{ENOTTY}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/9
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"} or $!{"ENOTTY"}
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"}
$!{"EINTR"} or $!{"EWOULDBLOCK"}
MC/DC0%0/4
$!{"EINTR"} or $!{"EWOULDBLOCK"} or $!{"EAGAIN"} or $!{"ENOTTY"}
$!{"EINTR"}
$!{"EWOULDBLOCK"}
$!{"EAGAIN"}
$!{"ENOTTY"}
Truth table0%0/5
A or B or C or D
A= $!{"EINTR"}B= $!{"EWOULDBLOCK"}C= $!{"EAGAIN"}D= $!{"ENOTTY"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | die "read failed: $!"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | ▶ | redo READ if $n == -1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | $complete++ if !$n; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | return \$buf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | $drop_connection++ unless $complete; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | @h = $socket->get_trailers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | ▶ | if (@h) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | local $HTTP::Headers::TRANSLATE_UNDERSCORE; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $response->push_header(@h); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | # keep-alive support | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | unless ($drop_connection) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | ▶ | if ($cache_key) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | my %connection = map { (lc($_) => 1) } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$response->header('Connection') || ''
MC/DC0%0/1
$response->header('Connection') || ''
$response->header('Connection')
Truth table0%0/2
A
A= $response->header('Connection')
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | split(/\s*,\s*/, ($response->header("Connection") || "")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | if (($peer_http_version eq "1.1" && !$connection{close}) || $connection{"keep-alive"}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$peer_http_version eq "1.1" and not $connection{"close"} or $connection{"keep-alive"}
$peer_http_version eq "1.1" and not $connection{"close"}
MC/DC0%0/3
$peer_http_version eq "1.1" and not $connection{"close"} or $connection{"keep-alive"}
$peer_http_version eq "1.1"
not $connection{"close"}
$connection{"keep-alive"}
Truth table0%0/5
A and not(B) or C
A= $peer_http_version eq "1.1"B= not $connection{"close"}C= $connection{"keep-alive"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $conn_cache->deposit($self->socket_type, $cache_key, $socket); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | $response; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | package LWP::Protocol::UWSGI::Socket; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 1 | ▶ | use base qw(IO::Socket::INET Net::HTTP); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | sub ping { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ping: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 0 | !$self->can_read(0); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | sub increment_response_count { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
increment_response_count: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | return ++${*$self}{'myhttp_response_count'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||