Subject: | Allow buffers in filter_last |
I'm trying to implement HTTP::Proxy::BodyFilter::throttle and have hit a limitation of HTTP::Proxy. My filter tries to emit a fixed maximum number of bytes per second. It accomplishes this via the filter() method by deferring some content to the buffer until enough time has passed (using sleep() perhaps). However, when the proxy has received all of the upstream data, it no longer permits use of the buffer and requires the filter to finish immediately.
I request that a while() loop be added around the filtering loop once the content is all received. That while loop should continue until all of the buffers are flushed.
Something roughly like this would work (untested):
sub filter_last {
my $self = shift;
return unless $self->{body}; # sanity check
my $i = 0;
my ( $data, $message, $protocol ) = @_;
for ( @{ $self->{current} } ) {
$$data = ${ $self->{buffers}[ $i ] } . $$data;
${ $self->{buffers}[ $i++ ] } = "";
$_->filter( $data, $message, $protocol, undef );
}
# call the cleanup routine if needed
for ( @{ $self->{current} } ) { $_->end if $_->can('end'); }
# clean up the mess for next time
$self->eod;
}