| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Compress::Deflate; |
|
2
|
1
|
|
|
1
|
|
1230
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
35
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use MRO::Compat; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
5
|
use Compress::Zlib (); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
455
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub finalize { |
|
9
|
0
|
|
|
0
|
1
|
|
my $c = shift; |
|
10
|
|
|
|
|
|
|
|
|
11
|
0
|
0
|
|
|
|
|
if ( $c->response->content_encoding ) { |
|
12
|
0
|
|
|
|
|
|
return $c->next::method(@_); |
|
13
|
|
|
|
|
|
|
} |
|
14
|
|
|
|
|
|
|
|
|
15
|
0
|
0
|
|
|
|
|
unless ( $c->response->body ) { |
|
16
|
0
|
|
|
|
|
|
return $c->next::method(@_); |
|
17
|
|
|
|
|
|
|
} |
|
18
|
|
|
|
|
|
|
|
|
19
|
0
|
0
|
|
|
|
|
unless ( $c->response->status == 200 ) { |
|
20
|
0
|
|
|
|
|
|
return $c->next::method; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
unless ( $c->response->content_type =~ /^text|xml$|javascript$/ ) { |
|
24
|
0
|
|
|
|
|
|
return $c->next::method; |
|
25
|
|
|
|
|
|
|
} |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
0
|
|
|
|
my $accept = $c->request->header('Accept-Encoding') || ''; |
|
28
|
|
|
|
|
|
|
|
|
29
|
0
|
0
|
|
|
|
|
unless ( index( $accept, "deflate" ) >= 0 ) { |
|
30
|
0
|
|
|
|
|
|
return $c->next::method; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my ( $d, $out, $status, $deflated ); |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
( $d, $status ) = Compress::Zlib::deflateInit( |
|
36
|
|
|
|
|
|
|
-WindowBits => -Compress::Zlib::MAX_WBITS(), |
|
37
|
|
|
|
|
|
|
); |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
0
|
|
|
|
|
unless ( $status == Compress::Zlib::Z_OK() ) { |
|
40
|
0
|
|
|
|
|
|
die("Cannot create a deflation stream. Error: $status"); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my $body = $c->response->body; |
|
44
|
0
|
0
|
|
|
|
|
eval { local $/; $body = <$body> } if ref $body; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
die "Response body is an unsupported kind of reference" if ref $body; |
|
46
|
0
|
|
|
|
|
|
( $out, $status ) = $d->deflate( $c->response->body ); |
|
47
|
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
unless ( $status == Compress::Zlib::Z_OK() ) { |
|
49
|
0
|
|
|
|
|
|
die("Deflation failed. Error: $status"); |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
$deflated .= $out; |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
( $out, $status ) = $d->flush; |
|
55
|
|
|
|
|
|
|
|
|
56
|
0
|
0
|
|
|
|
|
unless ( $status == Compress::Zlib::Z_OK() ) { |
|
57
|
0
|
|
|
|
|
|
die("Deflation failed. Error: $status"); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
$deflated .= $out; |
|
61
|
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
$c->response->body($deflated); |
|
63
|
0
|
|
|
|
|
|
$c->response->content_length( length($deflated) ); |
|
64
|
0
|
|
|
|
|
|
$c->response->content_encoding('deflate'); |
|
65
|
0
|
|
|
|
|
|
$c->response->headers->push_header( 'Vary', 'Accept-Encoding' ); |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
$c->next::method; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
1; |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
__END__ |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 NAME |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Catalyst::Plugin::Compress::Deflate - Deflate response |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
use Catalyst qw[Compress::Deflate]; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Deflate compress response if client supports it. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 METHODS |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head2 finalize |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
L<Catalyst>. |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHOR |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Christian Hansen, C<ch@ngmedia.com> |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 LICENSE |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This library is free software . You can redistribute it and/or modify it under |
|
102
|
|
|
|
|
|
|
the same terms as perl itself. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |