File Coverage

blib/lib/Plack/Middleware/ContentLength.pm
Criterion Covered Total %
statement 19 19 100.0
branch 2 2 100.0
condition 5 6 83.3
subroutine 6 6 100.0
pod 1 1 100.0
total 33 34 97.0


line stmt bran cond sub pod time code
1             package Plack::Middleware::ContentLength;
2 41     41   281 use strict;
  41         81  
  41         1457  
3 41     41   170 use warnings;
  41         83  
  41         2395  
4 41     41   205 use parent qw( Plack::Middleware );
  41         82  
  41         251  
5              
6 41     41   3342 use Plack::Util;
  41         81  
  41         10076  
7              
8             sub call {
9 709     709 1 1291 my $self = shift;
10 709         6583 my $res = $self->app->(@_);
11              
12             return $self->response_cb($res, sub {
13 672     672   1350 my $res = shift;
14 672         6401 my $h = Plack::Util::headers($res->[1]);
15 672 100 66     3760 if (!Plack::Util::status_with_no_entity_body($res->[0]) &&
      100        
16             !$h->exists('Content-Length') &&
17             !$h->exists('Transfer-Encoding') &&
18             defined(my $content_length = Plack::Util::content_length($res->[2]))) {
19 586         3762 $h->push('Content-Length' => $content_length);
20             }
21 672         32406 });
22             }
23              
24             1;
25              
26             __END__