blib/lib/Plack/Middleware/ContentMD5.pm untested

filter: Statementstmt 0.0% 0 / 28 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 43 CC 5 SCAR 27.7
CC
5
Cov
0%
call
30.0
BEGIN
2.0
BEGIN
2.0
CRAP 16.0
1 package Plack::Middleware::ContentMD5;
2  
3 use strict;
4 use warnings;
5 use parent qw( Plack::Middleware );
6  
7 use Plack::Util;
8 use Digest::MD5 qw/md5_hex/;
9  
10 sub call {
11 my $self = shift;
12 my $res = $self->app->(@_);
13
14 $self->response_cb($res, sub {
15 my $res = shift;
16  
17 return unless defined $res->[2];
18 return if (Plack::Util::status_with_no_entity_body($res->[0]));
19
20 my $h = Plack::Util::headers($res->[1]);
21 return if ( $h->exists('Content-MD5') );
22
23 my $body = $res->[2];
24 if (ref $body eq 'ARRAY') {
25 $h->set('Content-MD5', md5_hex(@$body));
26 }
27 # Do we need support $fh?
28  
29 return;
30 });
31 }
32  
33 1;
34  
35 __END__