Proxy.pm

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