| Catalyst-Plugin-Compress-Bzip2 documentation | Contained in the Catalyst-Plugin-Compress-Bzip2 distribution. |
Catalyst::Plugin::Compress::Bzip2 - Bzip2 response
use Catalyst qw[Compress::Bzip2];
Bzip2 compress response if client supports it.
Christian Hansen, ch@ngmedia.com
This library is free software . You can redistribute it and/or modify it under the same terms as perl itself.
| Catalyst-Plugin-Compress-Bzip2 documentation | Contained in the Catalyst-Plugin-Compress-Bzip2 distribution. |
package Catalyst::Plugin::Compress::Bzip2; use warnings; use strict; use MRO::Compat; use Compress::Bzip2 2.0 (); our $VERSION = '0.04'; sub finalize { my $c = shift; if ( $c->response->content_encoding ) { return $c->next::method(@_); } unless ( $c->response->body ) { return $c->next::method(@_); } unless ( $c->response->status == 200 ) { return $c->next::method(@_); } unless ( $c->response->content_type =~ /^text|xml$|javascript$/ ) { return $c->next::method(@_); } my $accept = $c->request->header('Accept-Encoding') || ''; unless ( index( $accept, "bzip2" ) >= 0 ) { return $c->next::method(@_); } $c->response->body( Compress::Bzip2::memBzip( $c->response->body ) ); $c->response->content_length( length( $c->response->body ) ); $c->response->content_encoding('bzip2'); $c->response->headers->push_header( 'Vary', 'Accept-Encoding' ); $c->next::method(@_); } 1; __END__