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 ge...@apache.org on 2004/03/04 16:16:10 UTC

cvs commit: modperl-2.0/t/htdocs/filter subrequest.txt

geoff       2004/03/04 07:16:10

  Modified:    .        Changes
  Added:       t/filter out_str_subreq_default.t out_str_subreq_modperl.t
               t/filter/TestFilter out_str_subreq_default.pm
                        out_str_subreq_modperl.pm
               t/htdocs/filter subrequest.txt
  Log:
  add tests for issuing subrequests from filters
  
  Revision  Changes    Path
  1.340     +2 -0      modperl-2.0/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/Changes,v
  retrieving revision 1.339
  retrieving revision 1.340
  diff -u -r1.339 -r1.340
  --- Changes	4 Mar 2004 06:01:05 -0000	1.339
  +++ Changes	4 Mar 2004 15:16:10 -0000	1.340
  @@ -12,6 +12,8 @@
   
   =item 1.99_13-dev
   
  +Added tests for issuing subrequests from filters [Geoffrey Young]
  +
   Updated to the new Apache License Version 2.0 [Gozer]
   
   Drop the support for making GATEWAY_INTERFACE special. It's not needed
  
  
  
  1.1                  modperl-2.0/t/filter/out_str_subreq_default.t
  
  Index: out_str_subreq_default.t
  ===================================================================
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestRequest;
  use Apache::TestUtil;
  
  plan tests => 1;
  
  my $location = '/TestFilter__out_str_subreq_default';
  
  my $content1    = "content\n";
  my $content2    = "more content\n";
  my $filter      = "filter\n";
  my $subrequest  = "default-handler subrequest\n";
  
  my $expected = join '', $content1, $subrequest, $content2, $filter;
  my $received = GET_BODY $location;
  
  ok t_cmp($expected, $received, 
      "testing filter-originated lookup_uri() call to core served URI");
  
  
  
  1.1                  modperl-2.0/t/filter/out_str_subreq_modperl.t
  
  Index: out_str_subreq_modperl.t
  ===================================================================
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestRequest;
  use Apache::TestUtil;
  
  plan tests => 1;
  
  my $location = '/TestFilter__out_str_subreq_modperl';
  
  my $content1    = "content\n";
  my $content2    = "more content\n";
  my $filter      = "filter\n";
  my $subrequest  = "modperl subrequest\n";
  
  my $expected = join '', $content1, $subrequest, $content2, $filter;
  my $received = GET_BODY $location;
  
  ok t_cmp($expected, $received, 
      "testing filter-originated lookup_uri() call to modperl-served URI");
  
  
  
  1.1                  modperl-2.0/t/filter/TestFilter/out_str_subreq_default.pm
  
  Index: out_str_subreq_default.pm
  ===================================================================
  package TestFilter::out_str_subreq_default;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  
  use Apache::RequestRec ();
  use Apache::RequestIO ();
  use Apache::SubRequest ();
  
  use Apache::Filter ();
  
  use Apache::Const -compile => qw(OK);
  
  # include the contents of a subrequest
  # in the filter, a la mod_include's 
  # <!--#include virtual="/subrequest" -->
  
  sub include {
  
      my $filter = shift;
  
      unless ($filter->ctx) {
          # don't forget to remove the C-L header
          $filter->r->headers_out->unset('Content-Length');
  
          $filter->ctx(1);
      }
  
      while ($filter->read(my $buffer, 1024)){
  
          if ($buffer eq "<tag>\n") {
              my $sub = $filter->r->lookup_uri('/default_subrequest/subrequest.txt');
              my $rc = $sub->run;
          }
          else {
             # send all other data along unaltered
             $filter->print($buffer);
          }
  
      }
  
      # add our own at the end
      if ($filter->seen_eos) {
          $filter->print("filter\n");
          $filter->ctx(1);
      }
  
      return Apache::OK;
  }
  
  sub response {
  
      my $r = shift;
  
      $r->content_type('text/plain');
  
      $r->print("content\n");
      $r->rflush;
      $r->print("<tag>\n");
      $r->rflush;
      $r->print("more content\n");
  
      Apache::OK;
  }
  1;
  __DATA__
  SetHandler modperl
  PerlModule              TestFilter::out_str_subreq_default
  PerlResponseHandler     TestFilter::out_str_subreq_default::response
  PerlOutputFilterHandler TestFilter::out_str_subreq_default::include
  
  Alias /default_subrequest @DocumentRoot@/filter
  <Location /default_subrequest>
    SetHandler default-handler
  </Location>
  
  
  
  1.1                  modperl-2.0/t/filter/TestFilter/out_str_subreq_modperl.pm
  
  Index: out_str_subreq_modperl.pm
  ===================================================================
  package TestFilter::out_str_subreq_modperl;
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  
  use Apache::RequestRec ();
  use Apache::RequestIO ();
  use Apache::SubRequest ();
  
  use Apache::Filter ();
  
  use Apache::Const -compile => qw(OK);
  
  # include the contents of a subrequest
  # in the filter, a la mod_include's 
  # <!--#include virtual="/subrequest" -->
  
  sub include {
  
      my $filter = shift;
  
      unless ($filter->ctx) {
          # don't forget to remove the C-L header
          $filter->r->headers_out->unset('Content-Length');
  
          $filter->ctx(1);
      }
  
      while ($filter->read(my $buffer, 1024)){
  
          if ($buffer eq "<tag>\n") {
              my $sub = $filter->r->lookup_uri('/modperl_subrequest');
              my $rc = $sub->run;
          }
          else {
             # send all other data along unaltered
             $filter->print($buffer);
          }
  
      }
  
      # add our own at the end
      if ($filter->seen_eos) {
          $filter->print("filter\n");
          $filter->ctx(1);
      }
  
      return Apache::OK;
  }
  
  sub subrequest {
  
      my $r = shift;
  
      $r->content_type('text/plain');
      $r->print("modperl subrequest\n");
  
      return Apache::OK;
  }
  
  sub response {
  
      my $r = shift;
  
      $r->content_type('text/plain');
  
      $r->print("content\n");
      $r->rflush;
      $r->print("<tag>\n");
      $r->rflush;
      $r->print("more content\n");
  
      Apache::OK;
  }
  1;
  __DATA__
  SetHandler modperl
  PerlModule              TestFilter::out_str_subreq_modperl
  PerlResponseHandler     TestFilter::out_str_subreq_modperl::response
  PerlOutputFilterHandler TestFilter::out_str_subreq_modperl::include
  
  <Location /modperl_subrequest>
    SetHandler modperl
    PerlResponseHandler   TestFilter::out_str_subreq_modperl::subrequest
  </Location>
  
  
  
  1.1                  modperl-2.0/t/htdocs/filter/subrequest.txt
  
  Index: subrequest.txt
  ===================================================================
  default-handler subrequest