Skip to content

Instantly share code, notes, and snippets.

@mattn
Created July 19, 2016 07:17
Show Gist options
  • Save mattn/b90695ebe448bc29b3d7623f7652fae9 to your computer and use it in GitHub Desktop.
Save mattn/b90695ebe448bc29b3d7623f7652fae9 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use YAML::Syck;
sub env_proxy {
require Encode;
require Encode::Locale;
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) {
warn "$k=$v";
}
}
}
#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};
warn "--- 1";
undef $ENV{REQUEST_METHOD};
undef $ENV{HTTP_PROXY};
undef $ENV{CGI_HTTP_PROXY};
env_proxy;
warn "--- 2";
$ENV{REQUEST_METHOD} = "GET";
undef $ENV{HTTP_PROXY};
undef $ENV{CGI_HTTP_PROXY};
env_proxy;
warn "--- 3";
undef $ENV{REQUEST_METHOD};
$ENV{HTTP_PROXY} = "http://proxy1.example.com";
undef $ENV{CGI_HTTP_PROXY};
env_proxy;
warn "--- 4";
$ENV{REQUEST_METHOD} = 'GET';
$ENV{HTTP_PROXY} = "http://proxy1.example.com";
undef $ENV{CGI_HTTP_PROXY};
env_proxy;
warn "--- 5";
undef $ENV{REQUEST_METHOD};
undef $ENV{HTTP_PROXY};
$ENV{CGI_HTTP_PROXY} = "http://proxy2.example.com";
env_proxy;
warn "--- 6";
$ENV{REQUEST_METHOD} = 'GET';
undef $ENV{HTTP_PROXY};
$ENV{CGI_HTTP_PROXY} = "http://proxy2.example.com";
env_proxy;
warn "--- 7";
undef $ENV{REQUEST_METHOD};
$ENV{HTTP_PROXY} = "http://proxy1.example.com";
$ENV{CGI_HTTP_PROXY} = "http://proxy2.example.com";
env_proxy;
warn "--- 8";
$ENV{REQUEST_METHOD} = "GET";
$ENV{HTTP_PROXY} = "http://proxy1.example.com";
$ENV{CGI_HTTP_PROXY} = "http://proxy2.example.com";
env_proxy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment