Created
July 19, 2016 15:35
-
-
Save mattn/2884397dd0ca977577cd1d0f7d9f32cc 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
From 9e671bb2dfb6a4817acd47281979be586d6bcbf8 Mon Sep 17 00:00:00 2001 | |
From: Yasuhiro Matsumoto <mattn.jp@gmail.com> | |
Date: Tue, 19 Jul 2016 12:22:18 +0900 | |
Subject: [PATCH] Add CGI_HTTP_PROXY | |
Need to be careful when called in the CGI environment as the HTTP_PROXY | |
variable is under control of that other guy. | |
--- | |
lib/Furl/HTTP.pm | 4 +++- | |
t/100_low/39_httpoxy.t | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ | |
2 files changed, 55 insertions(+), 1 deletion(-) | |
create mode 100644 t/100_low/39_httpoxy.t | |
diff --git a/lib/Furl/HTTP.pm b/lib/Furl/HTTP.pm | |
index 61fda59..37b7fc1 100644 | |
--- a/lib/Furl/HTTP.pm | |
+++ b/lib/Furl/HTTP.pm | |
@@ -208,7 +208,9 @@ sub make_x_www_form_urlencoded { | |
sub env_proxy { | |
my $self = shift; | |
- $self->{proxy} = $ENV{HTTP_PROXY} || ''; | |
+ local $ENV{HTTP_PROXY} if $ENV{REQUEST_METHOD}; | |
+ $self->{proxy} = $ENV{CGI_HTTP_PROXY} || ''; | |
+ $self->{proxy} ||= $ENV{http_proxy} || $ENV{HTTP_PROXY} || $self->{proxy}; | |
$self->{no_proxy} = $ENV{NO_PROXY} || ''; | |
$self; | |
} | |
diff --git a/t/100_low/39_httpoxy.t b/t/100_low/39_httpoxy.t | |
new file mode 100644 | |
index 0000000..b4fb5a8 | |
--- /dev/null | |
+++ b/t/100_low/39_httpoxy.t | |
@@ -0,0 +1,52 @@ | |
+use strict; | |
+use warnings; | |
+use Furl::HTTP; | |
+use Test::More; | |
+ | |
+plan tests => 8; | |
+ | |
+sub test_proxy { | |
+ my $expect = shift; | |
+ my $client = Furl::HTTP->new->env_proxy; | |
+ $client->{proxy}; | |
+} | |
+ | |
+undef $ENV{REQUEST_METHOD}; | |
+undef $ENV{HTTP_PROXY}; | |
+undef $ENV{CGI_HTTP_PROXY}; | |
+is test_proxy, ''; | |
+ | |
+$ENV{REQUEST_METHOD} = 'GET'; | |
+undef $ENV{HTTP_PROXY}; | |
+undef $ENV{CGI_HTTP_PROXY}; | |
+is test_proxy, ''; | |
+ | |
+undef $ENV{REQUEST_METHOD}; | |
+$ENV{HTTP_PROXY} = 'http://proxy1.example.com'; | |
+undef $ENV{CGI_HTTP_PROXY}; | |
+is test_proxy, 'http://proxy1.example.com'; | |
+ | |
+$ENV{REQUEST_METHOD} = 'GET'; | |
+$ENV{HTTP_PROXY} = 'http://proxy1.example.com'; | |
+undef $ENV{CGI_HTTP_PROXY}; | |
+is test_proxy, ''; | |
+ | |
+undef $ENV{REQUEST_METHOD}; | |
+undef $ENV{HTTP_PROXY}; | |
+$ENV{CGI_HTTP_PROXY} = 'http://proxy2.example.com'; | |
+is test_proxy, 'http://proxy2.example.com'; | |
+ | |
+$ENV{REQUEST_METHOD} = 'GET'; | |
+undef $ENV{HTTP_PROXY}; | |
+$ENV{CGI_HTTP_PROXY} = 'http://proxy2.example.com'; | |
+is test_proxy, 'http://proxy2.example.com'; | |
+ | |
+undef $ENV{REQUEST_METHOD}; | |
+$ENV{HTTP_PROXY} = 'http://proxy1.example.com'; | |
+$ENV{CGI_HTTP_PROXY} = 'http://proxy2.example.com'; | |
+is test_proxy, 'http://proxy2.example.com'; | |
+ | |
+$ENV{REQUEST_METHOD} = 'GET'; | |
+$ENV{HTTP_PROXY} = 'http://proxy1.example.com'; | |
+$ENV{CGI_HTTP_PROXY} = 'http://proxy2.example.com'; | |
+is test_proxy, 'http://proxy2.example.com'; | |
-- | |
2.9.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment