[Catalyst] patch: C::P::Compress::Deflate

Peter Karman peter at peknet.com
Tue Sep 19 17:17:58 CEST 2006


Patch below allows Compress::Deflate plugin to play nicely with Static::Simple 
and to allow for skipping deflation based on browser. Specifically, we found 
issues with older versions of IE that claimed to deal with the deflate encoding 
but balked.

I'm not sure if the way I detect presence of Static::Simple is the Right Way or 
not. Comments welcome.

--- /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 10:15:16.000000000 -0500
@@ -2,6 +2,8 @@

  use strict;

+our $VERSION = '0.02';
+
  use Compress::Zlib ();

  sub finalize {
@@ -29,6 +31,25 @@
          return $c->NEXT::finalize;
      }

+    # skip if using Static::Simple
+    if ( $c->can('_serve_static') ) {
+        $c->log->debug("skipping Compress::Deflate due to Static::Simple")
+          if $c->debug;
+        return $c->NEXT::finalize;
+    }
+
+    # skip if we have a particular browser type
+    if (    $c->request->browser
+        and $c->request->browser->windows
+        and $c->request->browser->ie
+        and $c->request->browser->major() <
+        ( $c->config->{compress}->{skip_ie} || 0 ) )
+    {
+        $c->log->debug("skipping Compress::Deflate due to skip_ie detection")
+          if $c->debug;
+        return $c->NEXT::finalize;
+    }
+
      my ( $d, $out, $status, $deflated );

      ( $d, $status ) = Compress::Zlib::deflateInit(
@@ -80,6 +101,21 @@

  Deflate compress response if client supports it.

+=head1 CONFIGURATION
+
+The config key B<compress> can be used. If you need to skip deflation for IE
+browsers, you can set the B<skip_ie> key to the major version below which you
+want to skip deflation.
+
+Example:
+
+ __PACKAGE__->config(  compress => { skip_ie => 6 }  )
+
+will skip deflation for all IE browsers below version 6.
+
+B<NOTE:> The B<skip_ie> feature requires the Catalyst::Plugin::Browser module.
+
+
  =head1 SEE ALSO

  L<Catalyst>.


-- 
Peter Karman  .  http://peknet.com/  .  peter at peknet.com



More information about the Catalyst mailing list