line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Compress::Gzip; |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
4195
|
use MRO::Compat; |
|
1
|
|
|
|
|
4489
|
|
|
1
|
|
|
|
|
56
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3111
|
use Compress::Zlib (); |
|
1
|
|
|
|
|
124214
|
|
|
1
|
|
|
|
|
346
|
|
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, "gzip" ) >= 0 ) { |
30
|
0
|
|
|
|
|
|
return $c->next::method(@_); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $body = $c->response->body; |
34
|
0
|
0
|
|
|
|
|
eval { local $/; $body = <$body> } if ref $body; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
die "Response body is an unsupported kind of reference" if ref $body; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
$c->response->body( Compress::Zlib::memGzip( $body ) ); |
38
|
0
|
|
|
|
|
|
$c->response->content_length( length( $c->response->body ) ); |
39
|
0
|
|
|
|
|
|
$c->response->content_encoding('gzip'); |
40
|
0
|
|
|
|
|
|
$c->response->headers->push_header( 'Vary', 'Accept-Encoding' ); |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$c->next::method(@_); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 NAME |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Catalyst::Plugin::Compress::Gzip - Gzip response |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=head1 SYNOPSIS |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
use Catalyst qw[Compress::Gzip]; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Gzip compress response if client supports it. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=head1 METHODS |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 finalize |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 SEE ALSO |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
L<Catalyst>. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 AUTHOR |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Christian Hansen, C<ch@ngmedia.com> |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 LICENSE |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
This library is free software . You can redistribute it and/or modify it under |
77
|
|
|
|
|
|
|
the same terms as perl itself. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |