You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl-cvs@perl.apache.org by st...@apache.org on 2003/01/29 02:04:34 UTC

cvs commit: modperl-2.0/src/modules/perl modperl_callback.c

stas        2003/01/28 17:04:34

  Modified:    .        Changes
               src/modules/perl modperl_callback.c
  Added:       t/hooks  stacked_handlers.t
               t/hooks/TestHooks stacked_handlers.pm
  Log:
  Stacked handlers chain execution is now aborted when a handler returns
  something other than OK or DECLINED
  
  Revision  Changes    Path
  1.116     +3 -0      modperl-2.0/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/Changes,v
  retrieving revision 1.115
  retrieving revision 1.116
  diff -u -r1.115 -r1.116
  --- Changes	25 Jan 2003 03:08:04 -0000	1.115
  +++ Changes	29 Jan 2003 01:04:33 -0000	1.116
  @@ -10,6 +10,9 @@
   
   =item 1.99_09-dev
   
  +Stacked handlers chain execution is now aborted when a handler returns
  +something other than OK or DECLINED [Stas]
  +
   make $filter->read() in input streaming filters, use the same number
   of arguments as read() in the output filters. [Stas]
   
  
  
  
  1.1                  modperl-2.0/t/hooks/stacked_handlers.t
  
  Index: stacked_handlers.t
  ===================================================================
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  use Apache::TestRequest;
  
  plan tests => 1;
  
  my $location = "/TestHooks::stacked_handlers";
  my $expected = join "\n", qw(one two three), '';
  my $received = GET_BODY $location;
  
  ok t_cmp($expected, $received, "stacked_handlers");
  
  
  
  1.1                  modperl-2.0/t/hooks/TestHooks/stacked_handlers.pm
  
  Index: stacked_handlers.pm
  ===================================================================
  package TestHooks::stacked_handlers;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::RequestRec ();
  use Apache::RequestIO ();
  
  use Apache::Const -compile => qw(OK DECLINED);
  
  sub handler {
      my $r = shift;
  
      $r->handler("modperl");
      $r->push_handlers(PerlResponseHandler => [\&one, \&two, \&three, \&four]);
  
      return Apache::OK;
  }
  
  sub one {
      my $r = shift;
  
      $r->content_type('text/plain');
      $r->print("one\n");
  
      return Apache::OK;
  }
  
  sub two {
      my $r = shift;
  
      $r->print("two\n");
  
      return Apache::OK;
  }
  
  sub three {
      my $r = shift;
  
      $r->print("three\n");
  
      return Apache::DONE;
  }
  
  # this one shouldn't get called, because the three has returned DONE
  sub four {
      my $r = shift;
  
      $r->print("four\n");
  
      return Apache::OK;
  }
  
  
  1;
  __DATA__
  <NoAutoConfig>
    <Location /TestHooks::stacked_handlers>
        SetHandler modperl
        PerlHeaderParserHandler TestHooks::stacked_handlers
    </Location>
  </NoAutoConfig>
  
  
  
  
  1.53      +12 -3     modperl-2.0/src/modules/perl/modperl_callback.c
  
  Index: modperl_callback.c
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/src/modules/perl/modperl_callback.c,v
  retrieving revision 1.52
  retrieving revision 1.53
  diff -u -r1.52 -r1.53
  --- modperl_callback.c	14 Jan 2003 06:42:43 -0000	1.52
  +++ modperl_callback.c	29 Jan 2003 01:04:33 -0000	1.53
  @@ -182,12 +182,21 @@
       handlers = (modperl_handler_t **)av->elts;
   
       for (i=0; i<nelts; i++) {
  -        if ((status = modperl_callback(aTHX_ handlers[i], p, r, s, av_args)) != OK) {
  +        status = modperl_callback(aTHX_ handlers[i], p, r, s, av_args);
  +        
  +        MP_TRACE_h(MP_FUNC, "%s returned %d\n", handlers[i]->name, status);
  +
  +        if ((status != OK) && (status != DECLINED)) {
               status = modperl_errsv(aTHX_ status, r, s);
  +#ifdef MP_TRACE
  +            if (i+1 != nelts) {
  +                MP_TRACE_h(MP_FUNC, "there were %d uncalled handlers\n",
  +                           nelts-i-1);
  +            }
  +#endif
  +            break;
           }
   
  -        MP_TRACE_h(MP_FUNC, "%s returned %d\n",
  -                   handlers[i]->name, status);
       }
   
       SvREFCNT_dec((SV*)av_args);