[Catalyst-commits] r13128 -
Catalyst-Plugin-Compress/trunk/lib/Catalyst/Plugin
xinming at dev.catalyst.perl.org
xinming at dev.catalyst.perl.org
Tue Apr 6 15:36:39 GMT 2010
Author: xinming
Date: 2010-04-06 16:36:39 +0100 (Tue, 06 Apr 2010)
New Revision: 13128
Modified:
Catalyst-Plugin-Compress/trunk/lib/Catalyst/Plugin/Compress.pm
Log:
better content_type handling for Catalyst::Plugin::Compress.
Modified: Catalyst-Plugin-Compress/trunk/lib/Catalyst/Plugin/Compress.pm
===================================================================
--- Catalyst-Plugin-Compress/trunk/lib/Catalyst/Plugin/Compress.pm 2010-04-03 03:04:05 UTC (rev 13127)
+++ Catalyst-Plugin-Compress/trunk/lib/Catalyst/Plugin/Compress.pm 2010-04-06 15:36:39 UTC (rev 13128)
@@ -68,6 +68,22 @@
$c->maybe::next::method(@_);
}
+use List::Util qw(first);
+sub should_compress_response {
+ my ($self) = @_;
+ my ($ct) = split /;/, $self->res->content_type;
+ my @compress_types = qw(
+ application/javascript
+ application/json
+ application/x-javascript
+ application/xml
+ );
+ return 1
+ if ($ct =~ m{^text/})
+ or ($ct =~ m{\+xml$}
+ or (first { lc($ct) eq $_ } @compress_types));
+}
+
sub finalize {
my $c = shift;
@@ -75,7 +91,7 @@
or $c->res->content_encoding
or (not $c->res->body)
or ($c->res->status != 200)
- or ($c->res->content_type !~ /^text|xml$|javascript|json$/)
+ or (not $c->should_compress_response)
) {
return $c->maybe::next::method(@_);
}
@@ -152,6 +168,12 @@
[error] Caught exception in engine "Wide character in subroutine entry at
/usr/lib/perl5/site_perl/5.8.8/Compress/Zlib.pm line xxx."
+=head1 INTERNAL METHODS
+
+=head2 should_compress_response
+
+This method determine wether compressing the reponse using this plugin.
+
=head1 SEE ALSO
L<Catalyst>.
More information about the Catalyst-commits
mailing list