Proxy.pm

filter: Statementstmt 91.0% 409 / 449 Branchbran 75.5% 136 / 180 Conditioncond 64.2% 36 / 56 MC/DCmcdc 35.4% 11 / 31 Subroutinesub 98.1% 53 / 54 Podpod 100% 13 / 13 totaltotal 84.0% 658 / 783 CC 125 SCAR 27.5
CC
125
Cov
85%
serve_connections
36.5
push_filter
27.5
__ANON__
25.0
CRAP 15.7
« Proxy/Engine/ScoreBoard.pm ↑ Summary Proxy/BodyFilter/save.pm »
1 package HTTP::Proxy;
2 67 $HTTP::Proxy::VERSION = '0.304';
3 67 ▶use HTTP::Daemon;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 67 ▶use HTTP::Date qw(time2str);
Subroutine BEGIN: called CC=1 SCAR=0.0
5 67 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 67 ▶use LWP::ConnCache;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 67 ▶use Fcntl ':flock'; # import LOCK_* constants
Subroutine BEGIN: called CC=1 SCAR=0.0
8 67 ▶use IO::Select;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 67 ▶use Sys::Hostname; # hostname()
Subroutine BEGIN: called CC=1 SCAR=0.0
10 67 ▶use Socket qw( SOL_SOCKET SO_SNDBUF SO_RCVBUF );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 67 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 67 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 67 ▶use vars qw( $VERSION @METHODS
Subroutine BEGIN: called CC=1 SCAR=0.0
15 67 @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS );
16  
17 67 require Exporter;
18 67 @ISA = qw(Exporter);
19 67 @EXPORT = (); # no export by default
20 67 @EXPORT_OK = qw( ERROR NONE PROXY STATUS PROCESS SOCKET HEADERS FILTERS
21 DATA CONNECT ENGINE ALL );
22 67 %EXPORT_TAGS = ( log => [@EXPORT_OK] ); # only one tag
23  
24 67 my $CRLF = "\015\012"; # "\r\n" is not portable
25  
26 # standard filters
27 67 ▶use HTTP::Proxy::HeaderFilter::standard;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 # constants used for logging
30 67 ▶use constant ERROR => -1; # always log
Subroutine BEGIN: called CC=1 SCAR=0.0
31 67 ▶use constant NONE => 0; # never log
Subroutine BEGIN: called CC=1 SCAR=0.0
32 67 ▶use constant PROXY => 1; # proxy information
Subroutine BEGIN: called CC=1 SCAR=0.0
33 67 ▶use constant STATUS => 2; # HTTP status
Subroutine BEGIN: called CC=1 SCAR=0.0
34 67 ▶use constant PROCESS => 4; # sub-process life (and death)
Subroutine BEGIN: called CC=1 SCAR=0.0
35 67 ▶use constant SOCKET => 8; # low-level connections
Subroutine BEGIN: called CC=1 SCAR=0.0
36 67 ▶use constant HEADERS => 16; # HTTP headers
Subroutine BEGIN: called CC=1 SCAR=0.0
37 67 ▶use constant FILTERS => 32; # Messages from filters
Subroutine BEGIN: called CC=1 SCAR=0.0
38 67 ▶use constant DATA => 64; # Data received by the filters
Subroutine BEGIN: called CC=1 SCAR=0.0
39 67 ▶use constant CONNECT => 128; # Data transmitted by the CONNECT method
Subroutine BEGIN: called CC=1 SCAR=0.0
40 67 ▶use constant ENGINE => 256; # Internal information from the Engine
Subroutine BEGIN: called CC=1 SCAR=0.0
41 67 ▶use constant ALL => 511; # All of the above
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43 # modules that need those constants to be defined
44 67 ▶use HTTP::Proxy::Engine;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 67 ▶use HTTP::Proxy::FilterStack;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 # Methods we can forward
48 67 my %METHODS;
49  
50 # HTTP (RFC 2616)
51 67 $METHODS{http} = [qw( CONNECT DELETE GET HEAD OPTIONS POST PUT TRACE )];
52  
53 # WebDAV (RFC 2518)
54 $METHODS{webdav} = [
55 67 @{ $METHODS{http} },
56 qw( COPY LOCK MKCOL MOVE PROPFIND PROPPATCH UNLOCK )
57 ];
58  
59 # Delta-V (RFC 3253)
60 $METHODS{deltav} = [
61 67 @{ $METHODS{webdav} },
62 qw( BASELINE-CONTROL CHECKIN CHECKOUT LABEL MERGE MKACTIVITY
63 MKWORKSPACE REPORT UNCHECKOUT UPDATE VERSION-CONTROL ),
64 ];
65  
66 # the whole method list
67 67 @METHODS = HTTP::Proxy->known_methods();
68  
69 # useful regexes (from RFC 2616 BNF grammar)
70 67 my %RX;
71 67 $RX{token} = qr/[-!#\$%&'*+.0-9A-Z^_`a-z|~]+/;
72 67 $RX{mime} = qr($RX{token}/$RX{token});
73 67 $RX{method} = '(?:' . join ( '|', @METHODS ) . ')';
74 67 $RX{method} = qr/$RX{method}/;
75  
76 71 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod documented
77 71 my $class = shift;
78 71 my %params = @_;
79  
80 # some defaults
81 71 my %defaults = (
82 agent => undef,
83 chunk => 4096,
84 daemon => undef,
85 host => 'localhost',
86 logfh => *STDERR,
87 logmask => NONE,
88 max_connections => 0,
89 max_keep_alive_requests => 10,
90 port => 8080,
91 stash => {},
92 timeout => 60,
93 via => undef,
94 x_forwarded_for => 1,
95 );
96  
97 # non modifiable defaults
98 71 my $self = bless { conn => 0, loop => 1 }, $class;
99  
100 # support for deprecated stuff
101 {
102 71 my %convert = (
103 maxchild => 'max_clients',
104 maxconn => 'max_connections',
105 maxserve => 'max_keep_alive_requests',
106 );
107 71 ▶ while( my ($old, $new) = each %convert ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %convert) 213 71 284
108 213 ▶ if( exists $params{$old} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{$old}) 5 208 213
109 5 $params{$new} = delete $params{$old};
110 5 carp "$old is deprecated, please use $new";
111 }
112 }
113 }
114  
115 # get attributes
116 $self->{$_} = exists $params{$_} ? delete( $params{$_} ) : $defaults{$_}
117 71 ▶ for keys %defaults;
Branch: 1 branch
BranchTrueFalseTotal
exists $params{$_} ? : 134 789 923
118  
119 71 ▶ if (!defined $self->{via}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"via"}) 70 1 71
120 $self->{via} =
121 hostname()
122 70 ▶ . ( $self->{port} != 80 ? ":$self->{port}" : '' )
Branch: 1 branch
BranchTrueFalseTotal
$self->{'port'} != 80 ? : 70 0 70
123 . " (HTTP::Proxy/$VERSION)";
124 }
125  
126 # choose an engine with the remaining parameters
127 71 $self->{engine} = HTTP::Proxy::Engine->new( %params, proxy => $self );
128 71 $self->log( PROXY, "PROXY", "Selected engine " . ref $self->{engine} );
129  
130 71 return $self;
131 }
132  
133 72 ▶sub known_methods {
Subroutine known_methods: called CC=5 SCAR=16.2
Pod documented
134 72 my ( $class, @args ) = @_;
135  
136 72 ▶ @args = map { lc } @args ? @args : ( keys %METHODS );
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 4 68 72
137 exists $METHODS{$_} || carp "Method group $_ doesn't exist"
138 72 ▶ for @args;
Branch: 1 branch
BranchTrueFalseTotal
exists $METHODS{$_} or carp("Method group $_ doesn't exist") 208 0 208
139 72 my %seen;
140 72 ▶ return grep { !$seen{$_}++ } map { @{ $METHODS{$_} || [] } } @args;
Condition50%1/2
$METHODS{$_} || []
l!l
2080
MC/DC0%0/1
$METHODS{$_} || []
$METHODS{$_}
Truth table50%1/2
A
A= $METHODS{$_}
Aresult
11
00
141 }
142  
143 62 ▶sub timeout {
Subroutine timeout: called CC=3 SCAR=11.0
Pod documented
144 62 my $self = shift;
145 62 my $old = $self->{timeout};
146 62 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 61 62
147 1 $self->{timeout} = shift;
148 1 ▶ $self->agent->timeout( $self->{timeout} ) if $self->agent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->agent 1 0 1
149 }
150 62 return $old;
151 }
152  
153 35 ▶sub url {
Subroutine url: called CC=2 SCAR=6.9
Pod documented
154 35 my $self = shift;
155 35 ▶ if ( not defined $self->daemon ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->daemon) 1 34 35
156 1 carp "HTTP daemon not started yet";
157 1 return undef;
158 }
159 34 return $self->daemon->url;
160 }
161  
162 # normal accessors
163 67 for my $attr ( qw(
164 agent chunk daemon host logfh port request response hop_headers
165 logmask via x_forwarded_for client_headers engine
166 max_connections max_keep_alive_requests
167 )
168 )
169 {
170 67 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
171 1072 ▶ *{"HTTP::Proxy::$attr"} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
172 2724 my $self = shift;
173 2724 my $old = $self->{$attr};
174 2724 ▶ $self->{$attr} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 419 2305 2724
175 2724 return $old;
176 }
177 1072 }
178  
179 # read-only accessors
180 67 for my $attr (qw( conn loop client_socket )) {
181 67 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
182 316 ▶ *{"HTTP::Proxy::$attr"} = sub { $_[0]{$attr} }
Subroutine __ANON__: called CC=1 SCAR=0.0
183 201 }
184  
185 4 ▶sub max_clients { shift->engine->max_clients( @_ ) }
Subroutine max_clients: called CC=1 SCAR=0.0
Pod documented
186  
187 # deprecated methods are still supported
188 {
189 67 my %convert = (
190 maxchild => 'max_clients',
191 maxconn => 'max_connections',
192 maxserve => 'max_keep_alive_requests',
193 );
194 67 ▶ while ( my ( $old, $new ) = each %convert ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %convert) 201 67 268
195 67 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
196 3 ▶ *$old = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
197 3 carp "$old is deprecated, please use $new";
198 3 goto \&$new;
199 201 };
200 }
201 }
202  
203 8 ▶sub stash {
Subroutine stash: called CC=3 SCAR=11.0
Pod documented
204 8 my $stash = shift->{stash};
205 8 ▶ return $stash unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 4 4 8
206 4 ▶ return $stash->{ $_[0] } if @_ == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 3 1 4
207 1 return $stash->{ $_[0] } = $_[1];
208 }
209  
210 6 ▶sub new_connection { ++$_[0]{conn} }
Subroutine new_connection: called CC=1 SCAR=0.0
Pod documented
211  
212 34 ▶sub start {
Subroutine start: called CC=6 SCAR=18.5
Pod documented
213 34 my $self = shift;
214  
215 34 $self->init;
216 0 ▶ $SIG{INT} = $SIG{TERM} = sub { $self->{loop} = 0 };
Subroutine __ANON__: not called CC=1 SCAR=1.2
217  
218 # the main loop
219 34 my $engine = $self->engine;
220 34 ▶ $engine->start if $engine->can('start');
Branch: 1 branch
BranchTrueFalseTotal
if $engine->can("start") 34 0 34
221 34 ▶ while( $self->loop ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->loop) 97 0 97
222 97 $engine->run;
223 75 ▶ last if $self->max_connections && $self->conn >= $self->max_connections;
Branch: 1 branch
BranchTrueFalseTotal
if $self->max_connections and $self->conn >= $self->max_connections 12 63 75
Condition66%2/3
$self->max_connections and $self->conn >= $self->max_connections
!ll&&!rl&&r
06312
MC/DC50%1/2
$self->max_connections and $self->conn >= $self->max_connections
$self->max_connections $self->conn >= $self->max_connections
Truth table66%2/3
A and B
A= $self->max_connectionsB= $self->conn >= $self->max_connections
ABresult
0X0
100
111
224 }
225 12 ▶ $engine->stop if $engine->can('stop');
Branch: 1 branch
BranchTrueFalseTotal
if $engine->can("stop") 12 0 12
226  
227 12 $self->log( STATUS, "STATUS",
228 "Processed " . $self->conn . " connection(s)" );
229  
230 12 return $self->conn;
231 }
232  
233 # semi-private init method
234 117 ▶sub init {
Subroutine init: called CC=4 SCAR=13.9
Pod documented
235 117 my $self = shift;
236  
237 # must be run only once
238 117 ▶ return if $self->{_init}++;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_init"}++ 58 59 117
239  
240 59 ▶ $self->_init_daemon if ( !defined $self->daemon );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->daemon 59 0 59
241 59 ▶ $self->_init_agent if ( !defined $self->agent );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->agent 59 0 59
242  
243 # specific agent config
244 59 $self->agent->requests_redirectable( [] );
245 59 $self->agent->agent(''); # for TRACE support
246 59 $self->agent->protocols_allowed( [qw( http https ftp gopher )] );
247  
248 # standard header filters
249 59 $self->{headers}{request} = HTTP::Proxy::FilterStack->new;
250 59 $self->{headers}{response} = HTTP::Proxy::FilterStack->new;
251  
252 # the same standard filter is used to handle headers
253 59 my $std = HTTP::Proxy::HeaderFilter::standard->new();
254 59 $std->proxy( $self );
255 59 ▶ $self->{headers}{request}->push( [ sub { 1 }, $std ] );
Subroutine __ANON__: called CC=1 SCAR=0.0
256 59 ▶ $self->{headers}{response}->push( [ sub { 1 }, $std ] );
Subroutine __ANON__: called CC=1 SCAR=0.0
257  
258 # standard body filters
259 59 $self->{body}{request} = HTTP::Proxy::FilterStack->new(1);
260 59 $self->{body}{response} = HTTP::Proxy::FilterStack->new(1);
261  
262 59 return;
263 }
264  
265 #
266 # private init methods
267 #
268  
269 61 ▶sub _init_daemon {
Subroutine _init_daemon: called CC=3 SCAR=11.2
270 61 my $self = shift;
271 61 my %args = (
272 LocalAddr => $self->host,
273 LocalPort => $self->port,
274 ReuseAddr => 1,
275 );
276 61 ▶ delete $args{LocalPort} unless $self->port; # 0 means autoselect
Branch: 1 branch
BranchTrueFalseTotal
unless $self->port 61 0 61
277 61 ▶ my $daemon = HTTP::Daemon->new(%args)
Branch: 1 branch
BranchTrueFalseTotal
my $daemon = "HTTP::Daemon"->new(%args) or die "Cannot initialize proxy daemon: $!" 61 0 61
278 or die "Cannot initialize proxy daemon: $!";
279 61 $self->daemon($daemon);
280  
281 61 return $daemon;
282 }
283  
284 61 ▶sub _init_agent {
Subroutine _init_agent: called CC=2 SCAR=7.0
285 61 my $self = shift;
286 61 ▶ my $agent = LWP::UserAgent->new(
Branch: 1 branch
BranchTrueFalseTotal
my $agent = "LWP::UserAgent"->new("env_proxy", 1, "keep_alive", 2, "parse_head", 0, "timeout", $self->timeout) or die "Cannot initialize proxy agent: $!" 61 0 61
287 env_proxy => 1,
288 keep_alive => 2,
289 parse_head => 0,
290 timeout => $self->timeout,
291 )
292 or die "Cannot initialize proxy agent: $!";
293 61 $self->agent($agent);
294 61 return $agent;
295 }
296  
297 # This is the internal "loop" that lets the child process process the
298 # incoming connections.
299  
300 28 ▶sub serve_connections {
Subroutine serve_connections: called CC=30 SCAR=36.0
Pod documented
301 28 my ( $self, $conn ) = @_;
302 28 my $response;
303 28 $self->{client_socket} = $conn; # read-only
304 28 $self->log( SOCKET, "SOCKET", "New connection from " . $conn->peerhost
305 . ":" . $conn->peerport );
306  
307 28 my ( $last, $served ) = ( 0, 0 );
308  
309 28 ▶ while ( $self->loop() ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->loop) 45 0 45
310 45 my $req;
311 {
312 45 local $SIG{INT} = local $SIG{TERM} = 'DEFAULT';
313 45 $req = $conn->get_request();
314 }
315  
316 45 $served++;
317  
318 # initialisation
319 45 $self->request($req);
320 45 $self->response(undef);
321  
322 # Got a request?
323 45 ▶ unless ( defined $req ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $req) 13 32 45
324 13 ▶ $self->log( SOCKET, "SOCKET",
Branch: 1 branch
BranchTrueFalseTotal
if $conn->reason ne "No more requests from this connection" 0 13 13
325 "Getting request failed: " . $conn->reason )
326 if $conn->reason ne 'No more requests from this connection';
327 13 return;
328 }
329 32 ▶ $self->log( STATUS, "REQUEST", $req->method . ' '
Branch: 1 branch
BranchTrueFalseTotal
$req->method eq 'CONNECT' ? : 1 31 32
330 . ( $req->method eq 'CONNECT' ? $req->uri->host_port : $req->uri ) );
331  
332 # can we forward this method?
333 32 ▶ if ( !grep { $_ eq $req->method } @METHODS ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq $req->method;} @HTTP::Proxy::METHODS) 0 32 32
334 0 $response = HTTP::Response->new( 501, 'Not Implemented' );
335 0 $response->content_type( "text/plain" );
336 0 $response->content(
337 "Method " . $req->method . " is not supported by this proxy." );
338 0 $self->response($response);
339 0 goto SEND;
340 }
341  
342 # transparent proxying support
343 32 ▶ if( not defined $req->uri->scheme ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $req->uri->scheme) 5 27 32
344 5 ▶ if( my $host = $req->header('Host') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $host = $req->header('Host')) { } 4 1 5
345 4 $req->uri->scheme( 'http' );
346 4 $req->uri->host( $host );
347 }
348 else {
349 1 $response = HTTP::Response->new( 400, 'Bad request' );
350 1 $response->content_type( "text/plain" );
351 1 $response->content("Can't do transparent proxying without a Host: header.");
352 1 $self->response($response);
353 1 goto SEND;
354 }
355 }
356  
357 # can we serve this protocol?
358 31 ▶ if ( !$self->is_protocol_supported( my $s = $req->uri->scheme ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_protocol_supported(my $s = $req->uri->scheme)) 1 30 31
359 {
360 # should this be 400 Bad Request?
361 1 $response = HTTP::Response->new( 501, 'Not Implemented' );
362 1 $response->content_type( "text/plain" );
363 1 $response->content("Scheme $s is not supported by this proxy.");
364 1 $self->response($response);
365 1 goto SEND;
366 }
367  
368 # select the request filters
369 30 $self->{$_}{request}->select_filters( $req ) for qw( headers body );
370  
371 # massage the request
372 30 $self->{headers}{request}->filter( $req->headers, $req );
373  
374 # FIXME I don't know how to get the LWP::Protocol object...
375 # NOTE: the request is always received in one piece
376 30 $self->{body}{request}->filter( $req->content_ref, $req, undef );
377 30 $self->{body}{request}->eod; # end of data
378 30 $self->log( HEADERS, "REQUEST", $req->headers->as_string );
379  
380 # CONNECT method is a very special case
381 30 ▶ if( ! defined $self->response and $req->method eq 'CONNECT' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->response and $req->method eq "CONNECT") 1 29 30
Condition66%2/3
not defined $self->response and $req->method eq "CONNECT"
!ll&&!rl&&r
0291
MC/DC50%1/2
not defined $self->response and $req->method eq "CONNECT"
not defined $self->response $req->method eq "CONNECT"
Truth table66%2/3
not(A) and B
A= not defined $self->responseB= $req->method eq "CONNECT"
ABresult
0X0
100
111
382 1 $last = $self->_handle_CONNECT($served);
383 1 ▶ return if $last;
Branch: 1 branch
BranchTrueFalseTotal
if $last 1 0 1
384 }
385  
386 # the header filters created a response,
387 # we won't contact the origin server
388 # FIXME should the response header and body be filtered?
389 29 ▶ goto SEND if defined $self->response;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->response 0 29 29
390  
391 # FIXME - don't forward requests to ourselves!
392  
393 # pop a response
394 29 my ( $sent, $chunked ) = ( 0, 0 );
395 $response = $self->agent->simple_request(
396 $req,
397 25 ▶ sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
398 25 my ( $data, $response, $proto ) = @_;
399  
400 # first time, filter the headers
401 25 ▶ if ( !$sent ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sent) 19 6 25
402 19 $sent++;
403 19 $self->response( $response );
404  
405 # select the response filters
406 $self->{$_}{response}->select_filters( $response )
407 19 for qw( headers body );
408  
409 $self->{headers}{response}
410 19 ->filter( $response->headers, $response );
411 19 ( $last, $chunked ) =
412 $self->_send_response_headers( $served );
413 }
414  
415 # filter and send the data
416 25 $self->log( DATA, "DATA",
417 "got " . length($data) . " bytes of body data" );
418 25 $self->{body}{response}->filter( \$data, $response, $proto );
419 25 ▶ if ($chunked) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunked) { } 20 5 25
420 20 ▶ printf $conn "%x$CRLF%s$CRLF", length($data), $data
Branch: 1 branch
BranchTrueFalseTotal
if length $data 20 0 20
421 if length($data); # the filter may leave nothing
422 }
423 5 else { print $conn $data; }
424 },
425 29 $self->chunk
426 );
427  
428 # remove the header added by LWP::UA before it sends the response back
429 29 $response->remove_header('Client-Date');
430  
431 # the callback is not called by LWP::UA->request
432 # in some cases (HEAD, redirect, error responses have no body)
433 29 ▶ if ( !$sent ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sent) 10 19 29
434 10 $self->response($response);
435 $self->{$_}{response}->select_filters( $response )
436 10 for qw( headers body );
437 $self->{headers}{response}
438 10 ->filter( $response->headers, $response );
439 }
440  
441 # do a last pass, in case there was something left in the buffers
442 29 my $data = ""; # FIXME $protocol is undef here too
443 29 $self->{body}{response}->filter_last( \$data, $response, undef );
444 29 ▶ if ( length $data ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $data) 0 29 29
445 0 ▶ if ($chunked) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunked) { } 0 0 0
446 0 printf $conn "%x$CRLF%s$CRLF", length($data), $data;
447 }
448 0 else { print $conn $data; }
449 }
450  
451 # last chunk
452 29 ▶ print $conn "0$CRLF$CRLF" if $chunked; # no trailers either
Branch: 1 branch
BranchTrueFalseTotal
if $chunked 17 12 29
453 29 $self->response($response);
454  
455 # what about X-Died and X-Content-Range?
456 29 ▶ if( my $died = $response->header('X-Died') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $died = $response->header("X-Died")) 0 29 29
457 0 $self->log( ERROR, "ERROR", $died );
458 0 $sent = 0;
459 0 $response = HTTP::Response->new( 500, "Proxy filter error" );
460 0 $response->content_type( "text/plain" );
461 0 $response->content($died);
462 0 $self->response($response);
463 }
464  
465 SEND:
466  
467 31 $response = $self->response ;
468  
469 # responses that weren't filtered through callbacks
470 # (empty body or error)
471 # FIXME some error response headers might not be filtered
472 31 ▶ if ( !$sent ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($sent) 12 19 31
473 12 ($last, $chunked) = $self->_send_response_headers( $served );
474 12 my $content = $response->content;
475 12 ▶ if ($chunked) {
Branch: 1 branch
BranchTrueFalseTotal
if ($chunked) { } 4 8 12
476 4 ▶ printf $conn "%x$CRLF%s$CRLF", length($content), $content
Branch: 1 branch
BranchTrueFalseTotal
if length $content 3 1 4
477 if length($content); # the filter may leave nothing
478 4 print $conn "0$CRLF$CRLF";
479 }
480 8 else { print $conn $content; }
481 }
482  
483 # FIXME ftp, gopher
484 31 ▶ $conn->print( $response->content )
Branch: 1 branch
BranchTrueFalseTotal
if defined $req->uri->scheme and $req->uri->scheme =~ /^(?:ftp|gopher)$/ and $response->is_success 0 31 31
Condition50%3/6
defined $req->uri->scheme and $req->uri->scheme =~ /^(?:ftp|gopher)$/ and $response->is_success
!ll&&!rl&&r
3100
defined $req->uri->scheme and $req->uri->scheme =~ /^(?:ftp|gopher)$/
!ll&&!rl&&r
1300
MC/DC0%0/3
defined $req->uri->scheme and $req->uri->scheme =~ /^(?:ftp|gopher)$/ and $response->is_success
defined $req->uri->scheme $req->uri->scheme =~ /^(?:ftp|gopher)$/ $response->is_success
Truth table50%2/4
A and B and C
A= defined $req->uri->schemeB= $req->uri->scheme =~ /^(?:ftp|gopher)$/C= $response->is_success
ABCresult
0XX0
10X0
1100
1111
485 if defined $req->uri->scheme
486 and $req->uri->scheme =~ /^(?:ftp|gopher)$/
487 and $response->is_success;
488  
489 31 ▶ $self->log( SOCKET, "SOCKET", "Connection closed by the proxy" ), last
Branch: 1 branch
BranchTrueFalseTotal
if $last or $served >= $self->max_keep_alive_requests 14 17 31
Condition100%3/3
$last or $served >= $self->max_keep_alive_requests
l!l&&r!l&&!r
6817
MC/DC100%2/2
$last or $served >= $self->max_keep_alive_requests
$last $served >= $self->max_keep_alive_requests
Truth table100%3/3
A or B
A= $lastB= $served >= $self->max_keep_alive_requests
ABresult
1X1
011
000
490 if $last || $served >= $self->max_keep_alive_requests;
491 }
492 14 ▶ $self->log( SOCKET, "SOCKET", "Connection closed by the client" )
Branch: 1 branch
BranchTrueFalseTotal
if not $last and $served < $self->max_keep_alive_requests 0 14 14
Condition66%2/3
not $last and $served < $self->max_keep_alive_requests
!ll&&!rl&&r
680
MC/DC0%0/2
not $last and $served < $self->max_keep_alive_requests
not $last $served < $self->max_keep_alive_requests
Truth table66%2/3
not(A) and B
A= not $lastB= $served < $self->max_keep_alive_requests
ABresult
0X0
100
111
493 if !$last
494 and $served < $self->max_keep_alive_requests;
495 14 $self->log( PROCESS, "PROCESS", "Served $served requests" );
496 14 $conn->close;
497 }
498  
499 # INTERNAL METHOD
500 # send the response headers for the proxy
501 # expects $served (number of requests served)
502 # returns $last and $chunked (last request served, chunked encoding)
503 32 ▶sub _send_response_headers {
Subroutine _send_response_headers: called CC=10 SCAR=23.2
504 32 my ( $self, $served ) = @_;
505 32 my ( $last, $chunked ) = ( 0, 0 );
506 32 my $conn = $self->client_socket;
507 32 my $response = $self->response;
508  
509 # correct headers
510 $response->remove_header("Content-Length")
511 32 ▶ if $self->{body}{response}->will_modify();
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"body"}{"response"}->will_modify 2 30 32
512 32 ▶ $response->header( Server => "HTTP::Proxy/$VERSION" )
Branch: 1 branch
BranchTrueFalseTotal
unless $response->header("Server") 9 23 32
513 unless $response->header( 'Server' );
514 32 ▶ $response->header( Date => time2str(time) )
Branch: 1 branch
BranchTrueFalseTotal
unless $response->header("Date") 7 25 32
515 unless $response->header( 'Date' );
516  
517 # this is adapted from HTTP::Daemon
518 0 ▶ if ( $conn->antique_client ) { $last++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->antique_client) { } 0 32 32
519 else {
520 32 my $code = $response->code;
521 32 $conn->send_status_line( $code, $response->message,
522 $self->request()->protocol() );
523 32 ▶ if ( $code =~ /^(1\d\d|[23]04)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($code =~ /^(1\d\d|[23]04)$/) { } 0 32 32
elsif ($response->request and $response->request->method eq 'HEAD') { } 4 28 32
524  
525 # make sure content is empty
526 0 $response->remove_header("Content-Length");
527 0 $response->content('');
528 }
529 ▶ elsif ( $response->request && $response->request->method eq "HEAD" )
Condition100%3/3
$response->request and $response->request->method eq "HEAD"
!ll&&!rl&&r
5234
MC/DC100%2/2
$response->request and $response->request->method eq "HEAD"
$response->request $response->request->method eq "HEAD"
Truth table100%3/3
A and B
A= $response->requestB= $response->request->method eq "HEAD"
ABresult
0X0
100
111
530 { # probably OK, says HTTP::Daemon
531 }
532 else {
533 28 ▶ if ( $conn->proto_ge("HTTP/1.1") ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conn->proto_ge('HTTP/1.1')) { } 22 6 28
534 22 $chunked++;
535 22 $response->push_header( "Transfer-Encoding" => "chunked" );
536 22 ▶ $response->push_header( "Connection" => "close" )
Branch: 1 branch
BranchTrueFalseTotal
if $served >= $self->max_keep_alive_requests 7 15 22
537 if $served >= $self->max_keep_alive_requests;
538 }
539 else {
540 6 $last++;
541 6 $conn->force_last_request;
542 }
543 }
544 32 print $conn $response->headers_as_string($CRLF);
545 32 print $conn $CRLF; # separates headers and content
546 }
547 32 $self->log( STATUS, "RESPONSE", $response->status_line );
548 32 $self->log( HEADERS, "RESPONSE", $response->headers->as_string );
549 32 return ($last, $chunked);
550 }
551  
552 # INTERNAL method
553 # FIXME no man-in-the-middle for now
554 1 ▶sub _handle_CONNECT {
Subroutine _handle_CONNECT: called CC=13 SCAR=32.1
555 1 my ($self, $served) = @_;
556 1 my $last = 0;
557  
558 1 my $conn = $self->client_socket;
559 1 my $req = $self->request;
560 1 my $upstream;
561  
562 # connect upstream
563 1 ▶ if ( my $up = $self->agent->proxy('http') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $up = $self->agent->proxy('http')) { } 0 1 1
564  
565 # clean up authentication info from proxy URL
566 0 $up =~ s{^http://[^/\@]*\@}{http://};
567  
568 # forward to upstream proxy
569 0 $self->log( PROXY, "PROXY",
570 "Forwarding CONNECT request to next proxy: $up" );
571 0 my $response = $self->agent->simple_request($req);
572  
573 # check the upstream proxy's response
574 0 my $code = $response->code;
575 0 ▶ if ( $code == 407 ) { # don't forward Proxy Authentication requests
Branch: 2 branches
BranchTrueFalseTotal
if ($code == 407) { } 0 0 0
elsif ($code != 200) { } 0 0 0
576 0 my $response_407 = $response->as_string;
577 0 $response_407 =~ s/^Client-.*$//mg;
578 0 $response = HTTP::Response->new(502);
579 0 $response->content_type("text/plain");
580 0 $response->content( "Upstream proxy ($up) "
581 . "requested authentication:\n\n"
582 . $response_407 );
583 0 $self->response($response);
584 0 return $last;
585 }
586 elsif ( $code != 200 ) { # forward every other failure
587 0 $self->response($response);
588 0 return $last;
589 }
590  
591 0 $upstream = $response->{client_socket};
592 }
593 else { # direct connection
594 1 $upstream = IO::Socket::INET->new( PeerAddr => $req->uri->host_port );
595 }
596  
597 # no upstream socket obtained
598 1 ▶ if( !$upstream ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($upstream) 0 1 1
599 0 my $response = HTTP::Response->new( 500 );
600 0 $response->content_type( "text/plain" );
601 0 $response->content( "CONNECT failed: $@");
602 0 $self->response($response);
603 0 return $last;
604 }
605  
606 1 $upstream->setsockopt( SOL_SOCKET, SO_SNDBUF,
607 $conn->getsockopt( SOL_SOCKET, SO_RCVBUF ) );
608  
609 # send the response headers (FIXME more headers required?)
610 1 my $response = HTTP::Response->new(200);
611 1 $self->response($response);
612 1 $self->{$_}{response}->select_filters( $response ) for qw( headers body );
613  
614 1 $self->_send_response_headers( $served );
615  
616 # we now have a TCP connection
617 1 $last = 1;
618  
619 1 my $select = IO::Select->new;
620 1 for ( $conn, $upstream ) {
621 2 $_->autoflush(1);
622 2 $_->blocking(0);
623 2 $select->add($_);
624 }
625  
626 # loop while there is data
627 1 ▶ while ( my @ready = $select->can_read ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@ready) = $select->can_read) 2 1 3
628 2 for (@ready) {
629 2 my $data = "";
630 2 ▶ my ($sock, $peer, $from ) = $conn eq $_
Branch: 1 branch
BranchTrueFalseTotal
$conn eq $_ ? : 0 2 2
631 ? ( $conn, $upstream, "client" )
632 : ( $upstream, $conn, "server" );
633  
634 # read the data
635 2 my $read = $sock->sysread( $data, 4096 );
636  
637 # check for errors
638 2 ▶ if(not defined $read ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $read) 0 2 2
639 0 $self->log( ERROR, "CONNECT", "Read undef from $from ($!)" );
640 0 next;
641 }
642  
643 # end of connection
644 2 ▶ if ( $read == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($read == 0) 1 1 2
645 1 $_->close for ( $sock, $peer );
646 1 $select->remove( $sock, $peer );
647 1 $self->log( SOCKET, "CONNECT", "Connection closed by the $from" );
648 1 $self->log( PROCESS, "PROCESS", "Served $served requests" );
649 1 next;
650 }
651  
652 # proxy the data
653 1 $self->log( CONNECT, "CONNECT", "$read bytes received from $from" );
654 1 $peer->syswrite($data, length $data);
655 }
656 }
657 1 $self->log( CONNECT, "CONNECT", "End of CONNECT proxyfication");
658 1 return $last;
659 }
660  
661 31 ▶sub push_filter {
Subroutine push_filter: called CC=24 SCAR=33.1
Pod documented
662 31 my $self = shift;
663 31 my %arg = (
664 mime => 'text/*',
665 method => join( ',', @METHODS ),
666 scheme => 'http',
667 host => '',
668 path => '',
669 query => '',
670 );
671  
672 # parse parameters
673 31 ▶ for( my $i = 0; $i < @_ ; $i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @_) 54 31 85
674 54 ▶ next if $_[$i] !~ /^(mime|method|scheme|host|path|query)$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[$i] =~ /^(mime|method|scheme|host|path|query)$/ 35 19 54
675 19 $arg{$_[$i]} = $_[$i+1];
676 19 splice @_, $i, 2;
677 19 $i -= 2;
678 }
679 31 ▶ croak "Odd number of arguments" if @_ % 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 1 30 31
680  
681 # the proxy must be initialised
682 30 $self->init;
683  
684 # prepare the variables for the closure
685 my ( $mime, $method, $scheme, $host, $path, $query ) =
686 30 @arg{qw( mime method scheme host path query )};
687  
688 30 ▶ if ( defined $mime && $mime ne '' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $mime and $mime ne "") 30 0 30
Condition33%1/3
defined $mime and $mime ne ""
!ll&&!rl&&r
0030
MC/DC0%0/2
defined $mime and $mime ne ""
defined $mime $mime ne ""
Truth table33%1/3
A and B
A= defined $mimeB= $mime ne ""
ABresult
0X0
100
111
689 30 ▶ $mime =~ m!/! or croak "Invalid MIME type definition: $mime";
Branch: 1 branch
BranchTrueFalseTotal
$mime =~ m[/] or croak("Invalid MIME type definition: $mime") 29 1 30
690 29 $mime =~ s/\*/$RX{token}/; #turn it into a regex
691 29 $mime = qr/^$mime(?:$|\s*;?)/;
692 }
693  
694 29 my @method = split /\s*,\s*/, $method;
695 29 ▶ for (@method) { croak "Invalid method: $_" if !/$RX{method}/ }
Branch: 1 branch
BranchTrueFalseTotal
unless /$RX{"method"}/ 1 703 704
696 28 ▶ $method = @method ? '(?:' . join ( '|', @method ) . ')' : '';
Branch: 1 branch
BranchTrueFalseTotal
@method ? : 28 0 28
697 28 $method = qr/^$method$/;
698  
699 28 my @scheme = split /\s*,\s*/, $scheme;
700 28 for (@scheme) {
701 28 ▶ croak "Unsupported scheme: $_"
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_protocol_supported($_) 1 27 28
702 if !$self->is_protocol_supported($_);
703 }
704 27 ▶ $scheme = @scheme ? '(?:' . join ( '|', @scheme ) . ')' : '';
Branch: 1 branch
BranchTrueFalseTotal
@scheme ? : 27 0 27
705 27 $scheme = qr/$scheme/;
706  
707 27 ▶ $host ||= '.*'; $host = qr/$host/i;
Condition100%2/2
$host ||= ".*"
l!l
225
MC/DC100%1/1
$host ||= ".*"
$host
Truth table100%2/2
A
A= $host
Aresult
11
00
708 27 ▶ $path ||= '.*'; $path = qr/$path/;
Condition50%1/2
$path ||= ".*"
l!l
027
MC/DC0%0/1
$path ||= ".*"
$path
Truth table50%1/2
A
A= $path
Aresult
11
00
709 27 ▶ $query ||= '.*'; $query = qr/$query/;
Condition50%1/2
$query ||= ".*"
l!l
027
MC/DC0%0/1
$query ||= ".*"
$query
Truth table50%1/2
A
A= $query
Aresult
11
00
710  
711 # push the filter and its match method on the correct stack
712 27 ▶ while(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 31 25 56
713 31 my ($message, $filter ) = (shift, shift);
714 31 ▶ croak "'$message' is not a filter stack"
Branch: 1 branch
BranchTrueFalseTotal
unless $message =~ /^(request|response)$/ 1 30 31
715 unless $message =~ /^(request|response)$/;
716  
717 30 ▶ croak "Not a Filter reference for filter queue $message"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $filter and $filter->isa("HTTP::Proxy::HeaderFilter") || $filter->isa("HTTP::Proxy::BodyFilter") 1 29 30
Condition66%4/6
ref $filter and $filter->isa("HTTP::Proxy::HeaderFilter") || $filter->isa("HTTP::Proxy::BodyFilter")
!ll&&!rl&&r
1029
$filter->isa("HTTP::Proxy::HeaderFilter") or $filter->isa("HTTP::Proxy::BodyFilter")
l!l&&r!l&&!r
10190
MC/DC33%1/3
ref $filter and $filter->isa("HTTP::Proxy::HeaderFilter") || $filter->isa("HTTP::Proxy::BodyFilter")
ref $filter $filter->isa("HTTP::Proxy::HeaderFilter") $filter->isa("HTTP::Proxy::BodyFilter")
Truth table75%3/4
A and B or C
A= ref $filterB= $filter->isa("HTTP::Proxy::HeaderFilter")C= $filter->isa("HTTP::Proxy::BodyFilter")
ABCresult
0XX0
1000
11X1
1011
718 unless ref( $filter )
719 && ( $filter->isa('HTTP::Proxy::HeaderFilter')
720 || $filter->isa('HTTP::Proxy::BodyFilter') );
721  
722 29 my $stack;
723 29 ▶ $stack = 'headers' if $filter->isa('HTTP::Proxy::HeaderFilter');
Branch: 1 branch
BranchTrueFalseTotal
if $filter->isa("HTTP::Proxy::HeaderFilter") 10 19 29
724 29 ▶ $stack = 'body' if $filter->isa('HTTP::Proxy::BodyFilter');
Branch: 1 branch
BranchTrueFalseTotal
if $filter->isa("HTTP::Proxy::BodyFilter") 19 10 29
725  
726 # MIME can only match on response
727 29 my $mime = $mime;
728 29 ▶ undef $mime if $message eq 'request';
Branch: 1 branch
BranchTrueFalseTotal
if $message eq "request" 1 28 29
729  
730 # compute the match sub as a closure
731 # for $self, $mime, $method, $scheme, $host, $path
732 18 ▶ my $match = sub {
Subroutine __ANON__: called CC=14 SCAR=32.2
733 18 ▶ return 0
Branch: 1 branch
BranchTrueFalseTotal
if defined $mime and not +($self->response->content_type || "") =~ /$mime/ 0 18 18
Condition40%2/5
defined $mime and not +($self->response->content_type || "") =~ /$mime/
!ll&&!rl&&r
0180
$self->response->content_type || ''
l!l
180
MC/DC0%0/2
defined $mime and not +($self->response->content_type || "") =~ /$mime/
defined $mime $self->response->content_type
Truth table33%1/3
A and not(B)
A= defined $mimeB= $self->response->content_type
ABresult
0X0
110
101
734 if ( defined $mime )
735 && ( $self->response->content_type || '' ) !~ $mime;
736 18 ▶ return 0 if ( $self->{request}->method || '' ) !~ $method;
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"request"}->method || "") =~ /$method/ 0 18 18
Condition50%1/2
$self->{'request'}->method || ''
l!l
180
MC/DC0%0/1
$self->{'request'}->method || ''
$self->{'request'}->method
Truth table50%1/2
A
A= $self->{'request'}->method
Aresult
11
00
737 18 ▶ return 0 if ( $self->{request}->uri->scheme || '' ) !~ $scheme;
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"request"}->uri->scheme || "") =~ /$scheme/ 0 18 18
Condition50%1/2
$self->{'request'}->uri->scheme || ''
l!l
180
MC/DC0%0/1
$self->{'request'}->uri->scheme || ''
$self->{'request'}->uri->scheme
Truth table50%1/2
A
A= $self->{'request'}->uri->scheme
Aresult
11
00
738 18 ▶ return 0 if ( $self->{request}->uri->authority || '' ) !~ $host;
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"request"}->uri->authority || "") =~ /$host/ 0 18 18
Condition100%2/2
$self->{'request'}->uri->authority || ''
l!l
153
MC/DC100%1/1
$self->{'request'}->uri->authority || ''
$self->{'request'}->uri->authority
Truth table100%2/2
A
A= $self->{'request'}->uri->authority
Aresult
11
00
739 18 ▶ return 0 if ( $self->{request}->uri->path || '' ) !~ $path;
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"request"}->uri->path || "") =~ /$path/ 0 18 18
Condition50%1/2
$self->{'request'}->uri->path || ''
l!l
180
MC/DC0%0/1
$self->{'request'}->uri->path || ''
$self->{'request'}->uri->path
Truth table50%1/2
A
A= $self->{'request'}->uri->path
Aresult
11
00
740 18 ▶ return 0 if ( $self->{request}->uri->query || '' ) !~ $query;
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"request"}->uri->query || "") =~ /$query/ 0 18 18
Condition50%1/2
$self->{'request'}->uri->query || ''
l!l
018
MC/DC0%0/1
$self->{'request'}->uri->query || ''
$self->{'request'}->uri->query
Truth table50%1/2
A
A= $self->{'request'}->uri->query
Aresult
11
00
741 18 return 1; # it's a match
742 29 };
743  
744 # push it on the corresponding FilterStack
745 29 $self->{$stack}{$message}->push( [ $match, $filter ] );
746 29 $filter->proxy( $self );
747 }
748 }
749  
750 59 ▶sub is_protocol_supported {
Subroutine is_protocol_supported: called CC=4 SCAR=13.9
Pod documented
751 59 my ( $self, $scheme ) = @_;
752 59 my $ok = 1;
753 59 ▶ if ( !$self->agent->is_protocol_supported($scheme) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->agent->is_protocol_supported($scheme)) 2 57 59
754  
755 # double check, in case a dummy scheme was added
756 # to be handled directly by a filter
757 2 $ok = 0;
758 2 ▶ $scheme eq $_ && $ok++ for @{ $self->agent->protocols_allowed };
Branch: 1 branch
BranchTrueFalseTotal
$scheme eq $_ and ++$ok 0 8 8
759 }
760 59 $ok;
761 }
762  
763 475 ▶sub log {
Subroutine log: called CC=5 SCAR=16.1
Pod documented
764 475 my $self = shift;
765 475 my $level = shift;
766 475 my $fh = $self->logfh;
767  
768 475 ▶ return unless $self->logmask & $level || $level == ERROR;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->logmask & $level or $level == -1 455 20 475
Condition100%3/3
$self->logmask & $level or $level == -1
l!l&&r!l&&!r
191455
MC/DC100%2/2
$self->logmask & $level or $level == -1
$self->logmask & $level $level == -1
Truth table100%3/3
A or B
A= $self->logmask & $levelB= $level == -1
ABresult
1X1
011
000
769  
770 20 my ( $prefix, $msg ) = ( @_, '' );
771 20 my @lines = split /\n/, $msg;
772 20 ▶ @lines = ('') if not @lines;
Branch: 1 branch
BranchTrueFalseTotal
unless @lines 0 20 20
773  
774 20 flock( $fh, LOCK_EX );
775 20 print $fh "[" . localtime() . "] ($$) $prefix: $_\n" for @lines;
776 20 flock( $fh, LOCK_UN );
777 }
778  
779 67 1;
780  
781 __END__
« Proxy/Engine/ScoreBoard.pm ↑ Summary Proxy/BodyFilter/save.pm »