1
package TestFilter::out_str_buffer;
3
# in this test we want to buffer the data, modify the length of the
4
# response, set the c-l header and make sure that the client sees the
7
# notice that a bucket brigades based filter must be used. The streaming
8
# API lets FLUSH buckets through which causes an early flush of HTTP
12
use warnings FATAL => 'all';
14
use Apache2::RequestRec ();
15
use Apache2::RequestIO ();
21
use TestCommon::Utils ();
23
use base qw(Apache2::Filter);
25
use Apache2::Const -compile => qw(OK M_POST);
26
use APR::Const -compile => ':common';
34
for (my $b = $bb->first; $b; $b = $bb->next($b)) {
35
$seen_eos++, last if $b->is_eos;
39
return (join('', @data), $seen_eos);
43
my($filter, $bb) = @_;
45
my $ctx = $filter->ctx;
47
# no need to unset the C-L header, since this filter makes sure to
48
# correct it before any headers go out.
50
# $filter->r->headers_out->unset('Content-Length');
53
my $data = exists $ctx->{data} ? $ctx->{data} : '';
55
my($bdata, $seen_eos) = flatten_bb($bb);
57
$data .= $bdata if $bdata;
60
my $len = length $data;
61
$filter->r->headers_out->set('Content-Length', $len);
62
$filter->print($data) if $data;
65
# store context for all but the last invocation
70
return Apache2::Const::OK;
76
$r->content_type('text/plain');
79
if ($r->method_number == Apache2::Const::M_POST) {
80
$data = TestCommon::Utils::read_post($r);
81
$r->headers_out->set('Content-Length' => length $data);
84
for my $chunk (split /0/, $data) {
86
$r->rflush; # so the filter reads a chunk at a time
89
return Apache2::Const::OK;
96
PerlModule TestFilter::out_str_buffer
97
PerlResponseHandler TestFilter::out_str_buffer::response