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

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



See below for my comments.
--Quentin
----- Original Message -----
From: "Bruce Van Allen" <bva@cruzio.com>
To: "Quentin Smith" <macmania@bit-net.com>; <macperl-webcgi@macperl.org>
Sent: Monday, June 26, 2000 11:54 AM
Subject: 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.
See below.
>
> >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.
>
There is no such thing as a "server redirect." All redirects are handled by
the client. Also, the message I put, "Move", does not mean anything to the
browser. I will say this: I made a mistake with the header. Instead of "HTTP
302" it should be "HTTP/1.0 301".
> 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.

I got my answers from my head, but you can check what I said by looking in
"Demo.acgi" in the "MacPerl CGI" folder in the MacPerl folder. There is an
if block that reads:
if ($query =~ /redirect/i) {
    if($header) {
        print "HTTP/1.0 301 Redirect$eol";
        print "Location:
http://$ENV{SERVER_NAME}:$ENV{SERVER_PORT}/Default.html$eol$eol";
        print "Go Away!$eol";
    } else {
        print "Location: /Default.html\n\nGo Away!\n";
    }
    exit;
}

I will also say this: You should use both a Location header and a URI
header:

HTTP/1.0 301 Redirect
Location: dummy.html
URL: dummy.html
Content-type: text/html
BLAH BLAH BLAH

The content will only be displayed by browsers whivh do not understand the
301 response code.

>
> 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