Subject: | http and https don't work correctly |
I just checked the latest version (3.10) source code and the two subs http and https still won't work properly. :-) Explanations and corrected examples follow:
# ORIGINAL
sub http {
my ($self,$parameter) = self_or_CGI(@_);
# emits a warning under -w if no parameter supplied
return $ENV{$parameter} if $parameter=~/^HTTP/;
# emits a warning under -w if no parameter supplied
$parameter =~ tr/-/_/;
return $ENV{"HTTP_\U$parameter\E"} if $parameter;
# that's a lot of work just to re-implement the built-in grep command
my(@p);
foreach (keys %ENV) {
# captures HTTPS variables as well
push(@p,$_) if /^HTTP/;
}
return @p;
}
# CORRECTED VERSION
sub http {
my ($self,$parameter) = self_or_CGI(@_);
if (defined $parameter) {
$parameter =~ tr/-a-z/_A-Z/;
return $ENV{$parameter} if $parameter =~ /^HTTP(?:_|$)/;
# I don't actually know of any webserver that sets this
# but it provides consistency with https
return $ENV{HTTP} if $parameter eq '';
return $ENV{"HTTP_$parameter"};
}
return grep { /^HTTP(?:_|$)/ } keys %ENV;
}
# ORIGINAL
sub https {
# this should've been an indication U were doing something wrong
local($^W)=0;
my ($self,$parameter) = self_or_CGI(@_);
# guess U didn't need to turn off warnings after all
# since U return right away, but what about the HTTPS_
# variables? e.g. HTTPS_KEYSIZE
return $ENV{HTTPS} unless $parameter;
return $ENV{$parameter} if $parameter=~/^HTTPS/;
$parameter =~ tr/-/_/;
return $ENV{"HTTPS_\U$parameter\E"} if $parameter;
# oh good, let's re-implement grep again
my(@p);
foreach (keys %ENV) {
push(@p,$_) if /^HTTPS/;
}
return @p;
}
# CORRECTED VERSION
sub https {
my ($self,$parameter) = self_or_CGI(@_);
if (defined $parameter) {
$parameter =~ tr/-a-z/_A-Z/;
return $ENV{$parameter} if $parameter =~ /^HTTPS(?:_|$)/;
return $ENV{HTTPS} if $parameter eq '';
return $ENV{"HTTPS_$parameter"};
}
return grep { /^HTTPS(?:_|$)/ } keys %ENV;
}