Peter Karman scribbled on 9/19/06 10:45 AM:
see
http://article.gmane.org/gmane.comp.web.catalyst.general/2089/match=static+simple+compress
I didn't see mention of any fix in the list archives, hence this patch.
To make some amends for my earlier bone-headedness, here's patches that actually
address this particular issue. It adds a 'no_types' config option to exclude
content types from compression that match 'text/' -- specifically CSS. It will
skip text/css by default.
I realize this doesn't address the question of best development practices, but
it does fix the bug in the email thread above.
--
Peter Karman . http://peknet.com/ . [EMAIL PROTECTED]
--- /usr/lib/perl5/site_perl/5.8.6/Catalyst/Plugin/Compress/Deflate.pm
2006-09-05 11:29:48.000000000 -0500
+++ Catalyst/Plugin/Compress/Deflate.pm 2006-09-19 15:03:49.000000000 -0500
@@ -2,8 +2,19 @@
use strict;
+our $VERSION = '0.02';
+
use Compress::Zlib ();
+sub setup
+{
+ my $c = shift;
+
+ $c->NEXT::setup(@_);
+
+ $c->config->{config}->{no_types} ||= [qw( text/css )];
+}
+
sub finalize {
my $c = shift;
@@ -23,6 +34,17 @@
return $c->NEXT::finalize;
}
+ for my $type (@{$c->config->{compress}->{no_types}||[]})
+ {
+ if ($c->response->content_type eq $type)
+ {
+ $c->log->debug("skipping Compress::Deflate due to match on type
$type")
+ if $c->debug;
+
+ return $c->NEXT::finalize;
+ }
+ }
+
my $accept = $c->request->header('Accept-Encoding') || '';
unless ( index( $accept, "deflate" ) >= 0 ) {
@@ -80,6 +102,21 @@
Deflate compress response if client supports it.
+=head1 CONFIGURATION
+
+The config key B<compress> stores all Compress Plugin options.
+
+=head2 Skip based on content type
+
+Not all B<text/*> content types should be compressed. By default
Compress::Deflate
+will skip all B<test/css> content types. You can configure more B<text/*>
types to skip
+with the B<no_types> option:
+
+ __PACKAGE__->config( compress => { no_types => [qw( text/plain text/css )]
} );
+
+B<NOTE:> If you must include B<text/css> explicitly if you set the B<no_types>
option.
+Otherwise it will be compressed.
+
=head1 SEE ALSO
L<Catalyst>.
--- /usr/lib/perl5/site_perl/5.8.6/Catalyst/Plugin/Compress/Gzip.pm
2006-09-05 11:29:48.000000000 -0500
+++ Catalyst/Plugin/Compress/Gzip.pm 2006-09-19 15:06:10.000000000 -0500
@@ -4,6 +4,16 @@
use Compress::Zlib ();
+sub setup
+{
+ my $c = shift;
+
+ $c->NEXT::setup(@_);
+
+ $c->config->{config}->{no_types} ||= [qw( text/css )];
+}
+
+
sub finalize {
my $c = shift;
@@ -23,6 +33,17 @@
return $c->NEXT::finalize;
}
+ for my $type (@{$c->config->{compress}->{no_types}||[]})
+ {
+ if ($c->response->content_type eq $type)
+ {
+ $c->log->debug("skipping Compress::Deflate due to match on type
$type")
+ if $c->debug;
+
+ return $c->NEXT::finalize;
+ }
+ }
+
my $accept = $c->request->header('Accept-Encoding') || '';
unless ( index( $accept, "gzip" ) >= 0 ) {
@@ -54,6 +75,21 @@
Gzip compress response if client supports it.
+=head1 CONFIGURATION
+
+The config key B<compress> stores all Compress Plugin options.
+
+=head2 Skip based on content type
+
+Not all B<text/*> content types should be compressed. By default
Compress::Deflate
+will skip all B<test/css> content types. You can configure more B<text/*>
types to skip
+with the B<no_types> option:
+
+ __PACKAGE__->config( compress => { no_types => [qw( text/plain text/css )]
} );
+
+B<NOTE:> If you must include B<text/css> explicitly if you set the B<no_types>
option.
+Otherwise it will be compressed.
+
=head1 SEE ALSO
L<Catalyst>.
_______________________________________________
List: [email protected]
Listinfo: http://lists.rawmode.org/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/[email protected]/
Dev site: http://dev.catalyst.perl.org/