Catalyst::Plugin::Compress::Bzip2 - Bzip2 response


Catalyst-Plugin-Compress-Bzip2 documentation Contained in the Catalyst-Plugin-Compress-Bzip2 distribution.

Index


Code Index:

NAME

Top

Catalyst::Plugin::Compress::Bzip2 - Bzip2 response

SYNOPSIS

Top

    use Catalyst qw[Compress::Bzip2];




DESCRIPTION

Top

Bzip2 compress response if client supports it.

METHODS

Top

finalize

SEE ALSO

Top

Catalyst.

AUTHOR

Top

Christian Hansen, ch@ngmedia.com

LICENSE

Top

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__