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

Creating a filter for all text/html files

Expand Messages
  • Scott Gifford
    Hello, I m working on moving a Web server to a new location, and to test it, I d like to use a simple filter to replace all references to the old server name
    Message 1 of 4 , Jan 30, 2005
    • 0 Attachment
      Hello,

      I'm working on moving a Web server to a new location, and to test it,
      I'd like to use a simple filter to replace all references to the old
      server name with the IP address of the new server. This is just for
      testing, so it's OK that it's not a perfect solution.

      Basically, I'm doing:

      s/(?:www\.)?sitename\.(?:com|net|org)/1.2.3.4/ig;

      I've got it working right now, but I'd like it to know the
      Content-Type that Apache would use for a document, so I can decide
      whether to filter it and so I can send a correct Content-Type header.

      I can try to guess the content-type from the filename (which is what
      I'm doing now), but I'd prefer not to re-implement Apache's system for
      deciding content types, and I'd also like it to Do The Right Thing for
      CGI/mod_perl scripts, where you can't tell by the filename what
      content-type they're going to output.

      Is there a way to do that?

      Thanks!

      ---ScottG.
    • Philippe M. Chiasson
      ... $r- content_type should tell you that. http://perl.apache.org/docs/2.0/api/Apache/RequestRec.html#C_content_type_ ... Yes, certainly a good idea not to do
      Message 2 of 4 , Feb 1, 2005
      • 0 Attachment
        Scott Gifford wrote:
        > Hello,
        >
        > [...]
        >
        > I've got it working right now, but I'd like it to know the
        > Content-Type that Apache would use for a document, so I can decide
        > whether to filter it and so I can send a correct Content-Type header.

        $r->content_type should tell you that.

        http://perl.apache.org/docs/2.0/api/Apache/RequestRec.html#C_content_type_

        > I can try to guess the content-type from the filename (which is what
        > I'm doing now), but I'd prefer not to re-implement Apache's system for
        > deciding content types, and I'd also like it to Do The Right Thing for
        > CGI/mod_perl scripts, where you can't tell by the filename what
        > content-type they're going to output.

        Yes, certainly a good idea not to do anything of the sort. Let Apache tell you
        that.

        --------------------------------------------------------------------------------
        Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
        http://gozer.ectoplasm.org/ F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5
      • Geoffrey Young
        ... in addition to what philippe said, Apache::Clean for mp2 should prove as a good example for you to follow:
        Message 3 of 4 , Feb 1, 2005
        • 0 Attachment
          > I can try to guess the content-type from the filename (which is what
          > I'm doing now), but I'd prefer not to re-implement Apache's system for
          > deciding content types, and I'd also like it to Do The Right Thing for
          > CGI/mod_perl scripts, where you can't tell by the filename what
          > content-type they're going to output.

          in addition to what philippe said, Apache::Clean for mp2 should prove as a
          good example for you to follow:

          http://search.cpan.org/~geoff/Apache-Clean-2.00_4/

          see also the two articles on perl.com that talk about this particular module:

          http://www.perl.com/pub/a/2003/04/17/filters.html
          http://www.perl.com/pub/a/2003/05/22/testing.html

          HTH

          --Geoff
        • Scott Gifford
          ... [...] Geoffrey Young writes: [...] ... Thanks very much! Both of these pointers were very helpful. I swear I tried looking at
          Message 4 of 4 , Feb 2, 2005
          • 0 Attachment
            "Philippe M. Chiasson" <gozer@...> writes:

            > Scott Gifford wrote:
            >> Hello,
            >> [...]
            >>
            >> I've got it working right now, but I'd like it to know the
            >> Content-Type that Apache would use for a document, so I can decide
            >> whether to filter it and so I can send a correct Content-Type header.
            >
            > $r->content_type should tell you that.
            >
            > http://perl.apache.org/docs/2.0/api/Apache/RequestRec.html#C_content_type_

            [...]

            Geoffrey Young <geoff@...> writes:

            [...]

            > in addition to what philippe said, Apache::Clean for mp2 should prove as a
            > good example for you to follow:
            >
            > http://search.cpan.org/~geoff/Apache-Clean-2.00_4/

            Thanks very much! Both of these pointers were very helpful. I swear
            I tried looking at content_type and it didn't work, but it must have
            been a bug somewhere else, because it works perfectly now.

            Thanks again!

            ---ScottG.
          Your message has been successfully submitted and would be delivered to recipients shortly.