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

Re: [MacPerl] MacHTTP CGI question revisited



At 13.57 97/5/1, David Ray wrote:
>At 8:13 AM 5/1/97, Chris Nandor wrote:
>> ...the reason
>> the info is not supplied in some of the variables is not because the
>> browser does not supply them, but because the glue does not supply them, I
>> think.
>
>That's correct. A previous version of MacPerl and/or the glue did send all
>the >ENV variables correctly. This is a known bug with the current
>release.

No, this is a different problem.  There are two.

1.)  BUG: The current MacPerl does not properly populate the %ENV hash from
the CGI glue.  That is a problem with the MacPerl program that Matthias is
planning on fixing, but not until Perl 5.004 is released, at which time
Matthias will release a new version of MacPerl.

However, this bug may be surpassed by calling %ENV keys directly instead of
trying to iterate through the hash in a loop.  i.e., instead of writing

        foreach (keys %ENV) {print "$ENV{$_}\n"}

try

        print "$ENV{REMOTE_ADDR}\n$ENV{REMOTE_HOST}\netc";



2.)  PROBLEM, NOT A BUG: The CGI glue only supplies a portion of the
possible environment variables.  For instance, Internet Explorer provides
environment variables describing the monitor resolution and screen depth.
But the CGI glue does not retrieve these variables, because it does not
retrieve any variables that it is not hardcoded to retrieve, so it will not
get those variables.

Remember that environment variables (in CGI work) are produced by both the
browser and the server software.  But the CGI must be able to access them.
MacPerl accesses them through the CGI glue, and the CGI glue does not
supply them all.

At least, this is my theory, from experience and looking at the CGI Script
extension through Script Editor.  I believe the only environment variables
you can get through the CGI Script glue are (if I am mistaken, please
correct me, someone):

        @ENV = qw(
                REMOTE_USER
                REMOTE_IDENT
                REMOTE_HOST
                REMOTE_ADDR
                SERVER_NAME
                SERVER_PORT
                SCRIPT_NAME
                CONTENT_TYPE
                REQUEST_METHOD
                HTTP_REFERER
                HTTP_USER_AGENT
                QUERY_STRING
        );

I do not think you will be able to get any other variables.  I am not sure
if REMOTE_IDENT works, it might.  I think REMOTE_ADDR and REMOTE_HOST are
the same thing according to the glue, and get the machine name if possible.

Anyway, if you want to get everything out of %ENV from your CGIs, do the
following after defining the above array:

        foreach $key (sort @ENV) {
                print "$key: $ENV{$key}\n";
        }

NOTE: I am using both @ENV and %ENV in that foreach loop.  @ENV supplies
the key names, and then %ENV supplies the values.   (Recall that just
because they are named the same thing, that does not mean they are related
in any way ... one is a hash, one is an array.)

Again, you cannot directly access the key names by using "keys %ENV"
because %ENV is not populated properly due to a bug in MacPerl that will
not be fixed until Perl 5.004 is finalized and Matthias can release a new
version of MacPerl based on thae 5.004 source.

#================================================================
Chris Nandor                                      pudge@pobox.com
PGP Key 1024/B76E72AD                           http://pudge.net/
Keyfingerprint = 08 24 09 0B CE 73 CA 10  1F F7 7F 13 81 80 B6 B6



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch