<commit_before>package TestFilter::in_str_declined;

use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestUtil;

use Apache::RequestRec ();
use Apache::RequestIO ();

use Apache::Filter ();

use Apache::Const -compile => qw(OK DECLINED M_POST);

# make sure that if the input filter returns DECLINED without
# reading/printing data the data flow is not broken
sub handler {
      my $filter = shift;

      my $ctx = $filter->ctx;
      $ctx->{invoked}++;
      $filter->ctx($ctx);

      # can't use $f->seen_eos, since we don't read the data, so
      # we have to set the note on each invocation
      $filter->r->notes->set(invoked => $ctx->{invoked});
      #warn "filter was invoked $ctx->{invoked} times\n";

      return Apache::DECLINED;
}

sub response {
    my $r = shift;

    plan $r, tests => 1;

    $r->content_type('text/plain');

    if ($r->method_number == Apache::M_POST) {
        # consume the data so the input filter is invoked
        my $data = ModPerl::Test::read_post($r);
    }

    # ~20k of input makes it four bucket brigades:
    #    - 2 full bucket brigades of 8k
    #    - 1 half full brigade ~4k
    #    - 1 bucket brigade with EOS bucket
    my $expected = 4;
    my $invoked = $r->notes->get('invoked') || 0;
    ok t_cmp($expected, $invoked, "input stream filter declined");

    Apache::OK;
}
1;
__DATA__
SetHandler modperl
PerlResponseHandler TestFilter::in_str_declined::response
<commit_msg>fix the test to work with Apache versions that end up splitting the request body in a different number of bbs, so we can't test the number. PR: Obtained from: Submitted by: Reviewed by:<commit_after>package TestFilter::in_str_declined;

use strict;
use warnings FATAL => 'all';

use Apache::Test;
use Apache::TestUtil;

use Apache::RequestRec ();
use Apache::RequestIO ();

use Apache::Filter ();

use Apache::Const -compile => qw(OK DECLINED M_POST);

# make sure that if the input filter returns DECLINED without
# reading/printing data the data flow is not broken
sub handler {
      my $filter = shift;

      my $ctx = $filter->ctx;
      $ctx->{invoked}++;
      $filter->ctx($ctx);

      # can't use $f->seen_eos, since we don't read the data, so
      # we have to set the note on each invocation
      $filter->r->notes->set(invoked => $ctx->{invoked});
      #warn "filter was invoked $ctx->{invoked} times\n";

      return Apache::DECLINED;
}

sub response {
    my $r = shift;

    plan $r, tests => 2;

    $r->content_type('text/plain');

    if ($r->method_number == Apache::M_POST) {
        # consume the data so the input filter is invoked
        my $data = ModPerl::Test::read_post($r);
        ok t_cmp(20000, length $data, "the request body received ok");
    }

    # ~20k of input makes it four bucket brigades:
    #    - 2 full bucket brigades of 8k
    #    - 1 half full brigade ~4k
    #    - 1 bucket brigade with EOS bucket
    # however different Apache versions may send extra bb or split
    # data differently so we can't rely on the exact count
    my $invoked = $r->notes->get('invoked') || 0;
    ok $invoked > 1;

    Apache::OK;
}
1;
__DATA__
SetHandler modperl
PerlResponseHandler TestFilter::in_str_declined::response

{'fraction_non_alphanumeric': 0.12317716413279553, 'fraction_numerical': 0.008377288240769469, 'mean_word_length': 3.1707632600258733, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6945583', 'n_tokens_mistral': 1066, 'n_tokens_neox': 1012, 'n_words': 359}