[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-WebCGI] Can a cgi script call an URL?



Responding to my response to  "Riccardo Perotti" <perotti@pobox.com>
At 9:01 AM 6/26/00, Quentin Smith wrote:
>What actually happens is this:
>
>Browser requests cgi script http://www.domain.com/cgi-bin/a.cgi
>Browser receives "Location: http://www.domain.com/cgi-bin/b.cgi?foo=bar\n\n"

Browser receives?? See below after your sample script.

>Browser requests cgi script http://www.domain.com/cgi-bin/b.cgi?foo=bar
>Browser displays results of b.cgi
>
>In essence, printing a Location header is exactly like the user typing the
>address specified into the location bar in his browser.

And to answer Riccardo's follow-up question, 'foo=bar' is accessed by 
b.cgi from $ENV{QUERY_STRING}. Also, from my previous example,

"Location: www.domain.com/another/path/b.cgi/morepath/datafile.txt\n\n";

everything after b.cgi/, in this example 'morepath/datafile.txt', 
goes into $ENV{PATH_INFO}, so you have a way to pass a filename to 
the second CGI.

Quentin sez:
>I noticed that you
>did not include http:// in the addresses you gave. If you do not include
>"http://" in the location, you will get unpredictable results, including
>most likely a 404 File Not Found error.

You are correct if the second CGI is not in the first CGI's webserver 
'space'. A valid relative reference works fine without "http://". My 
response to Riccardo used his original example, and I should have 
deleted the "www.domain.com" portion, which implies an absolute URL.

Quentin again:
>Note that if you print a Location
>header, you should print a short message explaining that your browser does
>not support "Location" headers and provide a link to the site:
>
>#!perl
># Simple script to auto redirect to a site
>$site = "http://www.domain.com/cgi-bin/b.cgi?foo=bar";
>print "HTTP 302 Move\n";
>print "Location: site\n";
>print "Content-type: text/html\n\n";
>print "Your browser does not support redirects. Please click on the
>following link to continue: ";
>print "<A HREF=\"$site\">$site</A>";
>__END__

Gee, this doesn't seem quite right, but maybe I've misapprehended the 
rule, as a judge once said to me :-). As I understood the original 
question, the CGI performing a server redirect wasn't responding to a 
moved or missing file, but rather has done some processing and by 
some logic has called the second CGI. I've deployed lots of CGIs that 
use dispatch tables to handle a variety of user actions, and 
sometimes a particular action is best handled by another CGI script.

As I understand it, the middle steps are taken by the server(s), and 
the user's browser doesn't get anything until the second CGI returns 
its output. Also, the rule I've followed for years is that when you 
use print "Location: ...", you can't use any other HTTP header lines, 
especially those related to content.

Not sure if this is where I first 'learned' all this, but see page 44 
ff. of Shishir Gundavaram's "CGI Programming on the World Wide Web", 
O'Reilly, 1996.

Please clarify.

1;





-- 

- Bruce

__Bruce_Van_Allen___bva@cruzio.com__Santa_Cruz_CA__

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org