stas        2003/10/06 18:04:13

  Modified:    src/modules/perl modperl_filter.c
               t/filter in_bbs_inject_header.t
               t/filter/TestFilter in_bbs_inject_header.pm
               .        Changes
  Log:
  - make sure that connection filters won't be inserted as request filters
  - adjust the test to die, if the connection filter that's designed to work
    only with HTTP headers, gets to read some request body (+test cleanup)
  
  Revision  Changes    Path
  1.72      +7 -0      modperl-2.0/src/modules/perl/modperl_filter.c
  
  Index: modperl_filter.c
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_filter.c,v
  retrieving revision 1.71
  retrieving revision 1.72
  diff -u -u -r1.71 -r1.72
  --- modperl_filter.c  7 Oct 2003 01:01:52 -0000       1.71
  +++ modperl_filter.c  7 Oct 2003 01:04:13 -0000       1.72
  @@ -900,6 +900,13 @@
                   continue;
               }
   
  +            if ((handlers[i]->attrs & MP_FILTER_CONNECTION_HANDLER)) {
  +                MP_TRACE_f(MP_FUNC,
  +                           "%s is not a FilterRequest handler\n",
  +                           handlers[i]->name);
  +                continue;
  +            }
  +
               /* XXX: I fail to see where this feature is used, since
                * modperl_filter_add_connection doesn't register request
                * filters. may be it'll be still useful when the same
  
  
  
  1.2       +2 -1      modperl-2.0/t/filter/in_bbs_inject_header.t
  
  Index: in_bbs_inject_header.t
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/filter/in_bbs_inject_header.t,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- in_bbs_inject_header.t    3 Oct 2003 22:41:39 -0000       1.1
  +++ in_bbs_inject_header.t    7 Oct 2003 01:04:13 -0000       1.2
  @@ -14,6 +14,7 @@
   
   my $config = Apache::Test::config();
   my $hostport = Apache::TestRequest::hostport($config);
  +my $content = "This body shouldn't be seen by the filter";
   t_debug("connecting to $hostport");
   
  -print POST_BODY_ASSERT $location, content => "whatever";
  +print POST_BODY_ASSERT $location, content => $content;
  
  
  
  1.2       +13 -14    modperl-2.0/t/filter/TestFilter/in_bbs_inject_header.pm
  
  Index: in_bbs_inject_header.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/filter/TestFilter/in_bbs_inject_header.pm,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- in_bbs_inject_header.pm   3 Oct 2003 22:41:39 -0000       1.1
  +++ in_bbs_inject_header.pm   7 Oct 2003 01:04:13 -0000       1.2
  @@ -19,7 +19,7 @@
   # and in the middle, whichever way you prefer.
   
   use strict;
  -use warnings;# FATAL => 'all';
  +use warnings FATAL => 'all';
   
   use base qw(Apache::Filter);
   
  @@ -43,6 +43,8 @@
       'X-Extra-Header3' => 'Value 3',
   );
   
  +my $request_body = "This body shouldn't be seen by the filter";
  +
   # returns 1 if a bucket with a header was inserted to the $bb's tail,
   # otherwise returns 0 (i.e. if there are no buckets to insert)
   sub inject_header_bucket {
  @@ -77,9 +79,6 @@
   
       debug join '', "-" x 20 , " filter called ", "-" x 20;
   
  -    use Data::Dumper;
  -    warn Dumper $filter->ctx;
  -
       my $ctx;
       unless ($ctx = $filter->ctx) {
           debug "filter context init";
  @@ -97,15 +96,14 @@
       # handling the HTTP request body
       if ($ctx->{done_with_headers}) {
           # XXX: when the bug in httpd filter will be fixed all the
  -        # code in this branch will be replaced with $filter->remove;
  +        # code in this branch will be replaced with:
  +        #   $filter->remove;
  +        #   return Apache::DECLINED;
           # at the moment (2.0.48) it doesn't work
           # so meanwhile tell the mod_perl filter core to pass-through
           # the brigade unmodified
           debug "passing the body through unmodified";
           return Apache::DECLINED;
  -        #my $rv = $filter->next->get_brigade($bb, $mode, $block, $readbytes);
  -        #return $rv unless $rv == APR::SUCCESS;
  -        #return Apache::OK;
       }
   
       # any custom HTTP header buckets to inject?
  @@ -131,10 +129,11 @@
   
           my $status = $bucket->read($data);
           debug "filter read:\n[$data]";
  +        return $status unless $status == APR::SUCCESS;
   
  -        if ($status != APR::SUCCESS) {
  -            return $status;
  -        }
  +        # check that we really work only on the headers
  +        die "This filter should not ever receive the request body, " .
  +            "but HTTP headers" if ($data||'') eq $request_body;
   
           if ($data and $data =~ /^POST/) {
               # demonstrate how to add a header while processing other headers
  @@ -186,10 +185,11 @@
   sub response {
       my $r = shift;
   
  +    my $data = ModPerl::Test::read_post($r);
  +
       plan $r, tests => 2 + keys %headers;
   
  -    my $data = ModPerl::Test::read_post($r);
  -    ok t_cmp(8, length($data), "whatever");
  +    ok t_cmp($request_body, $data);
   
       ok t_cmp($header1_val,
                $r->headers_in->get($header1_key),
  @@ -212,7 +212,6 @@
     # be set by the time the filter is inserted into the filter chain
     PerlModule TestFilter::in_bbs_inject_header
     PerlInputFilterHandler TestFilter::in_bbs_inject_header
  -
     <Location /TestFilter__in_bbs_inject_header>
        SetHandler modperl
        PerlResponseHandler TestFilter::in_bbs_inject_header::response
  
  
  
  1.228     +2 -0      modperl-2.0/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/Changes,v
  retrieving revision 1.227
  retrieving revision 1.228
  diff -u -u -r1.227 -r1.228
  --- Changes   2 Oct 2003 17:45:52 -0000       1.227
  +++ Changes   7 Oct 2003 01:04:13 -0000       1.228
  @@ -12,6 +12,8 @@
   
   =item 1.99_11-dev - 
   
  +make sure that connection filters won't be inserted as request filters [Stas]
  +
   Prevent the 'Use of uninitialized value.' warning when
   ModPerl::Util::exit is used. [Stas]
   
  
  
  

Reply via email to