dougm 01/07/15 15:39:37
Added: t/protocol echo_filter.t
t/protocol/TestProtocol echo_filter.pm
Log:
add filter-enabled echo protocol handler
Revision Changes Path
1.1 modperl-2.0/t/protocol/echo_filter.t
Index: echo_filter.t
===================================================================
use strict;
use warnings FATAL => 'all';
use Test;
use Apache::TestRequest ();
my @test_strings = qw(hello world);
plan tests => 1 + @test_strings;
my $socket = Apache::TestRequest::vhost_socket('TestProtocol::echo_filter');
ok $socket;
for (@test_strings) {
print "SEND ='$_'\n";
print $socket "$_\n";
chomp(my $reply = <$socket>);
print "REPLY='$reply'\n";
ok $reply eq $_;
}
1.1 modperl-2.0/t/protocol/TestProtocol/echo_filter.pm
Index: echo_filter.pm
===================================================================
package TestProtocol::echo_filter;
use strict;
use Apache::Connection ();
use APR::Bucket ();
use APR::Brigade ();
use APR::Const -compile => qw(SUCCESS);
use Apache::Const -compile => qw(MODE_BLOCKING);
use APR::Lib ();
sub handler {
my Apache::Connection $c = shift;
my $bb = APR::Brigade->new($c->pool);
for (;;) {
my $rv = $c->input_filters->get_brigade($bb,
Apache::MODE_BLOCKING);
if ($rv != APR::SUCCESS or $bb->empty) {
my $error = APR::strerror($rv);
warn "get_brigade: $error\n";
$bb->destroy;
last;
}
my $b = APR::Bucket::flush_create();
$bb->insert_tail($b);
$c->output_filters->pass_brigade($bb);
}
return Apache::OK;
}
1;