package Apache2::RemoveNextFilterIfNotTextHtml;

use strict;
use Apache2::Filter ();
use Apache2::FilterRec ();
use Apache2::RequestRec ();
use Apache2::Const -compile => qw(OK DECLINED);

sub handler {
  my $f   = shift;
  my $r   = $f->r;

  # we only process HTML documents
  unless( $r->content_type =~ m!text/html!i ) {
    eval {
      $f->next->remove;
    };
  }
  $f->remove;

  return Apache2::Const::DECLINED;
}

1;
