Comma Tool Setup

Hi,

  Regarding comma tools, I use a setup like

  <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond  %{QUERY_STRING} , [OR]
    RewriteCond  %{REQUEST_URI} ,
    RewriteRule (.*) /cgi-bin/r.pl [L]
  </IfModule>

this would call the r.pl script for all request URIs containing a comma,
regardless of whether in the path or the query string. This allows
combining scripts and comma tools and gives further flexibility for the
actual tool setup. It is possible to chain comma tools, for examle I can
do ,tidy,validate,validate to validate the Validators output for HTML
Tidy's output for some document; or I can pass parameters to comma tools
like ,xslt=http://example.org/tosvg,svg2png which would transform the
document using http://example.org/tosvg and convert the resulting SVG to
PNG using the ,svg2png tool...

I had to use a script here as I could not convince mod_rewrite to
properly escape the URI without using a RewriteMap (and RewriteMap is
not available from a .htaccess file...) It should be possible to do the
same without a script but it would probably be a bit more complicated...
The script is then something like

  #!perl -w
  use strict;
  use warnings;
  use URI::Escape 'uri_escape';
  
  sub tool
  {
    my $req = shift;
    return unless defined $req;
  
    my ($new, $tool, $param) = $req =~ /^(.*),(\w+)(?:=(.+?))?$/;
    return unless defined $tool;
  
    my %tools = map { split/\s+/ } <DATA> ;
    my $dst = $tools{$tool};
    return unless defined $dst;
  
    my $host = $ENV{HTTP_HOST} || $ENV{SERVER_NAME};
    return unless defined $host;
    $host =~ s/:\d+$//;
  
    $new = uri_escape("http://$host$new", "^A-Za-z0-9\-_.!~*'()");
    $param = uri_escape($param, "^A-Za-z0-9\-_.!~*'()");
  
    $dst =~ s:\$uri:$new:;
    $dst =~ s:\$param:$param: if defined $param;
  
    return $dst;
  }
  
  my $tool = tool $ENV{REQUEST_URI} ;
  if (not defined $tool)
  {
    print "Status: 404\n\n";
  }
  else
  {
    print "Status: 302\n";
    print "Location: $tool\n\n";
  }
  
  __DATA__
  links   http://www.google.com/search?q=link:$uri
  text    http://cgi.w3.org/cgi-bin/html2txt?url=$uri
  xslt    http://w3.org/2000/06/webdata/xslt?xslfile=$param&xmlfile=$uri
  ...

I could not convince Apache+SSL 1.3.12 to use this for URIs containing
query strings (i.e., the server just hangs) but it works flawlessly on
Apache 1.3.31 and Apache 2.0.48...

regards.

Received on Friday, 14 May 2004 10:53:18 UTC