-
-
Save karupanerura/6a0bdda4fcec67d79d33fe097a984431 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Encode; | |
use Encode::Locale; | |
use LWP::Protocol; | |
use URI; | |
sub dump_env { join ", ", map { "$_: ".($ENV{$_}||'(undef)') } qw/REQUEST_METHOD HTTP_PROXY CGI_HTTP_PROXY/ } | |
sub env_proxy { | |
my($k,$v); | |
while(($k, $v) = each %ENV) { | |
if ($ENV{REQUEST_METHOD}) { | |
# Need to be careful when called in the CGI environment, as | |
# the HTTP_PROXY variable is under control of that other guy. | |
next if $k =~ /^HTTP_/; | |
$k = "HTTP_PROXY" if $k eq "CGI_HTTP_PROXY"; | |
} | |
$k = lc($k); | |
next unless $k =~ /^(.*)_proxy$/; | |
$k = $1; | |
if ($k eq 'no') { | |
#$self->no_proxy(split(/\s*,\s*/, $v)); | |
} | |
elsif ($v) { | |
# Ignore random _proxy variables, allow only valid schemes | |
next unless $k =~ /^$URI::scheme_re\z/; | |
# Ignore xxx_proxy variables if xxx isn't a supported protocol | |
next unless LWP::Protocol::implementor($k); | |
warn "$v is used"; | |
} | |
} | |
} | |
#sub env_proxy { | |
# my $proxy = 'no proxy'; | |
# unless (defined $ENV{REQUEST_METHOD}) { | |
# $proxy = $ENV{HTTP_PROXY} || ''; | |
# } | |
# $proxy ||= $ENV{CGI_HTTP_PROXY}; | |
# warn $proxy || 'no proxy'; | |
#} | |
undef $ENV{FTP_PROXY}; | |
undef $ENV{HTTP_PROXY}; | |
undef $ENV{HTTPS_PROXY}; | |
undef $ENV{REQUEST_METHOD}; | |
undef $ENV{HTTP_PROXY}; | |
undef $ENV{CGI_HTTP_PROXY}; | |
warn "--- 1: ", dump_env; | |
env_proxy; | |
$ENV{REQUEST_METHOD} = "GET"; | |
undef $ENV{HTTP_PROXY}; | |
undef $ENV{CGI_HTTP_PROXY}; | |
warn "--- 2: ", dump_env; | |
env_proxy; | |
undef $ENV{REQUEST_METHOD}; | |
$ENV{HTTP_PROXY} = "HTTP_PROXY"; | |
undef $ENV{CGI_HTTP_PROXY}; | |
warn "--- 3: ", dump_env; | |
env_proxy; | |
$ENV{REQUEST_METHOD} = 'GET'; | |
$ENV{HTTP_PROXY} = "HTTP_PROXY"; | |
undef $ENV{CGI_HTTP_PROXY}; | |
warn "--- 4: ", dump_env; | |
env_proxy; | |
undef $ENV{REQUEST_METHOD}; | |
undef $ENV{HTTP_PROXY}; | |
$ENV{CGI_HTTP_PROXY} = "CGI_HTTP_PROXY"; | |
warn "--- 5: ", dump_env; | |
env_proxy; | |
$ENV{REQUEST_METHOD} = 'GET'; | |
undef $ENV{HTTP_PROXY}; | |
$ENV{CGI_HTTP_PROXY} = "CGI_HTTP_PROXY"; | |
warn "--- 6: ", dump_env; | |
env_proxy; | |
undef $ENV{REQUEST_METHOD}; | |
$ENV{HTTP_PROXY} = "HTTP_PROXY"; | |
$ENV{CGI_HTTP_PROXY} = "CGI_HTTP_PROXY"; | |
warn "--- 7: ", dump_env; | |
env_proxy; | |
$ENV{REQUEST_METHOD} = "GET"; | |
$ENV{HTTP_PROXY} = "HTTP_PROXY"; | |
$ENV{CGI_HTTP_PROXY} = "CGI_HTTP_PROXY"; | |
warn "--- 8: ", dump_env; | |
env_proxy; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
result: