Loading ...
Sorry, an error occurred while loading the content.

regular expressions on $Response ?

Expand Messages
  • Andrew Koebrick
    Hoping somebody can offer a suggestion on how best to do my headers and footers. I bumped into problems getting Apache::ASP, Apache 2.0 and filters working.
    Message 1 of 5 , Dec 14, 2004
    • 0 Attachment

      Hoping somebody can offer a suggestion on how best to do my headers and footers.  I bumped into problems getting Apache::ASP, Apache 2.0 and filters working.  I was using mod_ext_filter to replace my <body> and </body> tags (using a simple sed command) with a SSI directive, which in turn pulled in complex headers and footers. 

       

      When I moved to Fedora 3 this scheme started failing.  My options are to move off of Apache::ASP for my embedded perl (perhaps to Mason), or to try to do the replaces above in a manner more internal to Apache::ASP.

       

      I have not been using the $Response->AddHeader($name, $value)  because I need to keep the existing headers from the HTML files (they contain lots of metadata.

       

      So, is there a way to do regular expressions agains the $Resoponse object?  Something akin to (escaping ignored):

      $Response =~ s/<body>/<!--#include virtual='/inc/header.inc'-><body>/g

       

      I am not currently using a global.asa file, but I guess I could start if I need to.

       

      Thanks for any suggestions.

       

      Andrew Koebrick

      Andrew Koebrick
      Web Coordinator / Librarian

      Dept. of Administration
      State of
      Minnesota
      658 Cedar St.
      St. Paul, MN 55155

      651-296-4156
      http://server.admin.state.mn.us

       

       

       

      Andrew Koebrick
      Web Coordinator / Librarian

      Dept. of Administration
      State of
      Minnesota
      658 Cedar St.
      St. Paul, MN 55155

      651-296-4156
      http://server.admin.state.mn.us

       

    • John Drago
      In your globa.asa: use vars qw/ $Request $Response $Session $Server $Application /; Script_OnFlush { my $ref = $Response- {BinaryRef}; $$ref =~
      Message 2 of 5 , Dec 14, 2004
      • 0 Attachment
        In your globa.asa:

        use vars qw/
        $Request
        $Response
        $Session
        $Server
        $Application
        /;

        Script_OnFlush
        {
        my $ref = $Response->{BinaryRef};
        $$ref =~ s/<body>/<!--#include virtual='/inc/header.inc'-><body>/g;
        }# end Script_OnFlush()


        Regards,
        John Drago


        ________________________________________
        From: Andrew Koebrick [mailto:Andrew.Koebrick@...]
        Sent: Tuesday, December 14, 2004 3:31 PM
        To: 'asp@...'
        Subject: regular expressions on $Response ?

        Hoping somebody can offer a suggestion on how best to do my headers and footers.  I bumped into problems getting Apache::ASP, Apache 2.0 and filters working.  I was using mod_ext_filter to replace my <body> and </body> tags (using a simple sed command) with a SSI directive, which in turn pulled in complex headers and footers. 
         
        When I moved to Fedora 3 this scheme started failing.  My options are to move off of Apache::ASP for my embedded perl (perhaps to Mason), or to try to do the replaces above in a manner more internal to Apache::ASP.
         
        I have not been using the $Response->AddHeader($name, $value)  because I need to keep the existing headers from the HTML files (they contain lots of metadata.
         
        So, is there a way to do regular expressions agains the $Resoponse object?  Something akin to (escaping ignored):
        $Response =~ s/<body>/<!--#include virtual='/inc/header.inc'-><body>/g
         
        I am not currently using a global.asa file, but I guess I could start if I need to.
         
        Thanks for any suggestions.
         
        Andrew Koebrick
        Andrew Koebrick
        Web Coordinator / Librarian

        Dept. of Administration
        State of Minnesota
        658 Cedar St.
        St. Paul, MN 55155

        651-296-4156
        http://server.admin.state.mn.us
         
         
         
        Andrew Koebrick
        Web Coordinator / Librarian

        Dept. of Administration
        State of Minnesota
        658 Cedar St.
        St. Paul, MN 55155

        651-296-4156
        http://server.admin.state.mn.us
         

        ---------------------------------------------------------------------
        To unsubscribe, e-mail: asp-unsubscribe@...
        For additional commands, e-mail: asp-help@...
      • Seib, Broc
        Hi Andrew, I have written a mod_perl handler (using Apache::Filter) to inject a header/footer includes onto the content of any .asp file. So my .asp files
        Message 3 of 5 , Dec 15, 2004
        • 0 Attachment
          Hi Andrew,

          I have written a mod_perl handler (using Apache::Filter) to inject a
          header/footer includes onto the content of any .asp file. So my .asp
          files don't even contain the <html><head></head><body> </body> tags. The
          mod_perl handler literally injects <!--#include file=xxx--> lines into
          the filter stack and expects Apache::ASP to expand it. (In my config
          below, it would inject three include lines at the top for "all.inc",
          "head.inc", and "nav.inc", then at the end inject an include for
          "foot.inc".)

          So to write a new page, I just write an .asp file for the guts of the
          page and the header/footer/navigation areas automatically show up (and
          can even have their own state). There is nothing in the .asp file that
          refers to the header/footer; it is conpletely in the config file.

          I still use this in production at http://www.community-art.com/, using
          Apache::ASP version 2.47 and apache 1.3.x. I don't know if it is
          compatible with the more recent versions of Apache::ASP & apache 2.x
          mod_perl.

          Here's my httpd.conf setup, and mod_perl handler code following:


          ## ASP setup
          <FilesMatch "\.asp$">
          SetHandler perl-script
          PerlModule Apache::Filter
          PerlModule Apache::ASP

          PerlSetVar Filter On
          PerlSetVar AutoHeaders On
          PerlSetVar AutoHeadersHeadFile all.inc,head.inc,nav.inc
          PerlSetVar AutoHeadersFootFile foot.inc

          ## stack handlers for auto header/nav/footer
          ## note Apache::ASP sandwiched in the middle
          PerlHandler Apache::FilterHeader Apache::ASP Apache::FilterSendHeader

          ####
          ## more Apache::ASP setup...
          ####

          </FilesMatch>

          ## popup windows have different headers and footers
          ## put those .asp files in a /popup subdir
          <LocationMatch .*/popup/.*>
          PerlSetVar AutoHeaders On
          PerlSetVar AutoHeadersHeadFile all.inc,pophead.inc
          PerlSetVar AutoHeadersFootFile popfoot.inc
          </LocationMatch>

          ## we want some places to not have any header footer stuff happen.
          ## put those .asp files in a /no subdirectory and deal with the
          ## <html>, <head>, <body> tags yourself.
          <LocationMatch .*/no/.*>
          PerlSetVar AutoHeaders On
          PerlSetVar AutoHeadersHeadFile none
          PerlSetVar AutoHeadersFootFile none
          </LocationMatch>





          ---------- Apache::FilterHandler -----------
          package Apache::FilterHeader;

          use strict;
          use Apache::Constants qw(:common);
          use Apache::Log;

          sub handler {
          my $r = shift;
          $r = $r->filter_register(); ## returns Apache::Filter subclass of
          Apache
          ## $r->deterministic(1);

          my $file = $r->filename();
          return DECLINED unless ( $file =~ /(\.asp|\..*html)$/ );

          ## be sure we want auto headers here.
          my $AutoHeaders = $r->dir_config('AutoHeaders') || 'Off';
          my $auto = 0;
          if ( $AutoHeaders =~ m/^on$/io ) {
          $auto = 1;
          }
          return DECLINED unless ( $auto );

          ## get our header and footer file
          ## check the notes() for printer-friendly settings
          my $pf_headinc = $r->pnotes('pf_HEADER');
          my $pf_footinc = $r->pnotes('pf_FOOTER');
          #my $n = $r->pnotes();
          #for ( keys %$n ) {
          # $r->log->notice("pnotes($_)=$n->{$_}");
          #}
          #$r->log->notice("pf_footer=$pf_footinc");

          my $headinc = $pf_headinc || $r->dir_config('AutoHeadersHeadFile')
          || '';
          my $footinc = $pf_footinc || $r->dir_config('AutoHeadersFootFile')
          || '';


          ## ok, here we go...
          $r->content_type("text/html");
          # $r->send_http_header;
          my ($fh, $status) = $r->filter_input();

          if ( $status != OK ) {
          ## some kind of error
          #return $status;
          print <$fh>, "\n";
          return OK; ## let Apache::ASP pick it up from here...
          } else {
          my @X = (); ## dummy just to get header includes to be dynamic

          ## normal
          if ( $headinc and $headinc !~ /^none$/io ) {
          my @h = split(',',$headinc);
          for ( @h ) {
          print "<!--#include file=$_ args=@X-->\n";
          }
          }
          print <$fh>, "\n";
          if ( $footinc and $footinc !~ /^none$/io ) {
          my @h = split(',',$footinc);
          for ( @h ) {
          print "<!--#include file=$_ args=@X-->\n";
          }
          }
          return OK;
          }

          }
          1;


          ---------- Apache::FilterSendHeader -----------
          package Apache::FilterSendHeader;

          use strict;
          use Apache::Constants qw(:common);
          use Apache::Log;

          sub handler {
          my $r = shift;
          $r = $r->filter_register(); ## returns Apache::Filter subclass of
          Apache
          ## $r->deterministic(1);

          my $file = $r->filename();
          return DECLINED unless ( $file =~ /(\.asp|\..*html)$/ );

          ## be sure we want auto headers here.
          my $AutoHeaders = $r->dir_config('AutoHeaders') || 'Off';
          my $auto = 0;
          if ( $AutoHeaders =~ m/^on$/io ) {
          $auto = 1;
          }
          #print $r->log->notice("autoheaders=$auto");
          return DECLINED unless ( $auto );

          ## ok, here we go...
          # $r->content_type("text/html");
          $r->send_http_header;
          my ($fh, $status) = $r->filter_input();

          if ( $status != OK ) {
          ## some kind of error
          return $status;
          } else {
          ## normal
          #print $r->log->notice($r->filename);
          print <$fh>, "\n";
          return OK;
          }

          }
          1;





          I have since created a better "stacking" strategy since in java, but I
          have not ported it to perl. (This is the "Stack" tag library in
          WebGUI.jar from http://www.vyking.com/projects/WebGUI/CURRENT/. These
          have *no* docs yet besides the code.) The way I'd like see it
          implemented is an Apache 2.x mod_perl handler that walks the tree
          looking for filenames to accumlate based on the numbered filename
          convention demonstrated in the Stack taglib.

          -broc



          > -----Original Message-----
          > From: Andrew Koebrick [mailto:Andrew.Koebrick@...]
          > Sent: Tuesday, December 14, 2004 5:31 PM
          > To: 'asp@...'
          > Subject: regular expressions on $Response ?
          >
          >
          > Hoping somebody can offer a suggestion on how best to do my
          > headers and footers. I bumped into problems getting
          > Apache::ASP, Apache 2.0 and filters working. I was using
          > mod_ext_filter to replace my <body> and </body> tags (using a
          > simple sed command) with a SSI directive, which in turn
          > pulled in complex headers and footers.
          >
          >
          >
          > When I moved to Fedora 3 this scheme started failing. My
          > options are to move off of Apache::ASP for my embedded perl
          > (perhaps to Mason), or to try to do the replaces above in a
          > manner more internal to Apache::ASP.
          >
          >
          >
          > I have not been using the $Response->AddHeader($name, $value)
          > because I need to keep the existing headers from the HTML
          > files (they contain lots of metadata.
          >
          >
          >
          > So, is there a way to do regular expressions agains the
          > $Resoponse object? Something akin to (escaping ignored):
          >
          > $Response =~ s/<body>/<!--#include virtual='/inc/header.inc'-><body>/g
          >
          >
          >
          > I am not currently using a global.asa file, but I guess I
          > could start if I need to.
          >
          >
          >
          > Thanks for any suggestions.
          >
          >
          >
          > Andrew Koebrick
          >
          > Andrew Koebrick
          > Web Coordinator / Librarian
          >
          > Dept. of Administration
          > State of Minnesota
          > 658 Cedar St.
          > St. Paul, MN 55155
          >
          > 651-296-4156
          > http://server.admin.state.mn.us
          >
          >
          >
          >
          >
          >
          >
          > Andrew Koebrick
          > Web Coordinator / Librarian
          >
          > Dept. of Administration
          > State of Minnesota
          > 658 Cedar St.
          > St. Paul, MN 55155
          >
          > 651-296-4156
          > http://server.admin.state.mn.us
          >
          >
          >
          >

          ---------------------------------------------------------------------
          To unsubscribe, e-mail: asp-unsubscribe@...
          For additional commands, e-mail: asp-help@...
        • John Drago
          Woops -- that should have been: In your globa.asa: use vars qw/ $Request $Response $Session $Server $Application /; # Added sub infront of Script_OnFlush :)
          Message 4 of 5 , Dec 15, 2004
          • 0 Attachment
            Woops -- that should have been:

            In your globa.asa:

            use vars qw/
            $Request
            $Response
            $Session
            $Server
            $Application
            /;

            # Added "sub" infront of Script_OnFlush :)
            sub Script_OnFlush
            {
            my $ref = $Response->{BinaryRef};
            $$ref =~ s/<body>/<!--#include virtual='/inc/header.inc'-><body>/g;
            }# end Script_OnFlush()


            Regards,
            John Drago


            ________________________________________
            From: Andrew Koebrick [mailto:Andrew.Koebrick@...]
            Sent: Tuesday, December 14, 2004 3:31 PM
            To: 'asp@...'
            Subject: regular expressions on $Response ?

            Hoping somebody can offer a suggestion on how best to do my headers and footers.  I bumped into problems getting Apache::ASP, Apache 2.0 and filters working.  I was using mod_ext_filter to replace my <body> and </body> tags (using a simple sed command) with a SSI directive, which in turn pulled in complex headers and footers. 
             
            When I moved to Fedora 3 this scheme started failing.  My options are to move off of Apache::ASP for my embedded perl (perhaps to Mason), or to try to do the replaces above in a manner more internal to Apache::ASP.
             
            I have not been using the $Response->AddHeader($name, $value)  because I need to keep the existing headers from the HTML files (they contain lots of metadata.
             
            So, is there a way to do regular expressions agains the $Resoponse object?  Something akin to (escaping ignored):
            $Response =~ s/<body>/<!--#include virtual='/inc/header.inc'-><body>/g
             
            I am not currently using a global.asa file, but I guess I could start if I need to.
             
            Thanks for any suggestions.
             
            Andrew Koebrick
            Andrew Koebrick
            Web Coordinator / Librarian

            Dept. of Administration
            State of Minnesota
            658 Cedar St.
            St. Paul, MN 55155

            651-296-4156
            http://server.admin.state.mn.us
             
             
             
            Andrew Koebrick
            Web Coordinator / Librarian

            Dept. of Administration
            State of Minnesota
            658 Cedar St.
            St. Paul, MN 55155

            651-296-4156
            http://server.admin.state.mn.us
             

            ---------------------------------------------------------------------
            To unsubscribe, e-mail: asp-unsubscribe@...
            For additional commands, e-mail: asp-help@...



            ---------------------------------------------------------------------
            To unsubscribe, e-mail: asp-unsubscribe@...
            For additional commands, e-mail: asp-help@...
          • Andrew Koebrick
            Thanks- I had caught the missing sub. All appears well with my Rube Golberg templating system. Many thanks for the assistance. Andrew Koebrick Web
            Message 5 of 5 , Dec 15, 2004
            • 0 Attachment
              Thanks- I had caught the missing sub. All appears well with my Rube Golberg
              templating system. Many thanks for the assistance.

              Andrew Koebrick
              Web Coordinator / Librarian

              Dept. of Administration
              State of Minnesota
              658 Cedar St.
              St. Paul, MN 55155

              651-296-4156
              http://server.admin.state.mn.us


              -----Original Message-----
              From: John Drago [mailto:john.drago@...]
              Sent: Wednesday, December 15, 2004 12:27 PM
              To: Andrew Koebrick; asp@...
              Subject: RE: regular expressions on $Response ?

              Woops -- that should have been:

              In your globa.asa:

              use vars qw/
              $Request
              $Response
              $Session
              $Server
              $Application
              /;

              # Added "sub" infront of Script_OnFlush :)
              sub Script_OnFlush
              {
              my $ref = $Response->{BinaryRef};
              $$ref =~ s/<body>/<!--#include virtual='/inc/header.inc'-><body>/g;
              }# end Script_OnFlush()


              Regards,
              John Drago


              ________________________________________
              From: Andrew Koebrick [mailto:Andrew.Koebrick@...]
              Sent: Tuesday, December 14, 2004 3:31 PM
              To: 'asp@...'
              Subject: regular expressions on $Response ?

              Hoping somebody can offer a suggestion on how best to do my headers and
              footers.  I bumped into problems getting Apache::ASP, Apache 2.0 and filters
              working.  I was using mod_ext_filter to replace my <body> and </body> tags
              (using a simple sed command) with a SSI directive, which in turn pulled in
              complex headers and footers. 
               
              When I moved to Fedora 3 this scheme started failing.  My options are to
              move off of Apache::ASP for my embedded perl (perhaps to Mason), or to try
              to do the replaces above in a manner more internal to Apache::ASP.
               
              I have not been using the $Response->AddHeader($name, $value)  because I
              need to keep the existing headers from the HTML files (they contain lots of
              metadata.
               
              So, is there a way to do regular expressions agains the $Resoponse object? 
              Something akin to (escaping ignored):
              $Response =~ s/<body>/<!--#include virtual='/inc/header.inc'-><body>/g
               
              I am not currently using a global.asa file, but I guess I could start if I
              need to.
               
              Thanks for any suggestions.
               
              Andrew Koebrick
              Andrew Koebrick
              Web Coordinator / Librarian

              Dept. of Administration
              State of Minnesota
              658 Cedar St.
              St. Paul, MN 55155

              651-296-4156
              http://server.admin.state.mn.us
               
               
               
              Andrew Koebrick
              Web Coordinator / Librarian

              Dept. of Administration
              State of Minnesota
              658 Cedar St.
              St. Paul, MN 55155

              651-296-4156
              http://server.admin.state.mn.us
               

              ---------------------------------------------------------------------
              To unsubscribe, e-mail: asp-unsubscribe@...
              For additional commands, e-mail: asp-help@...


              ---------------------------------------------------------------------
              To unsubscribe, e-mail: asp-unsubscribe@...
              For additional commands, e-mail: asp-help@...
            Your message has been successfully submitted and would be delivered to recipients shortly.