From a3388b68b7d2babce3d696cacb3e4cbfcd898490 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 25 Nov 2003 08:53:42 +0000 Subject: [PATCH] * lib/open-uri.rb (URI::Generic#find_proxy): use http_proxy under CGI if the environment variable is case sensitive. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ lib/open-uri.rb | 33 ++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index a9b71760b3..f542abfce9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Nov 25 17:52:11 2003 Tanaka Akira + + * lib/open-uri.rb (URI::Generic#find_proxy): use http_proxy under CGI + if the environment variable is case sensitive. + Tue Nov 25 16:41:33 2003 NAKAMURA, Hiroshi * test/wsdl/multiplefault.wsdl, test/wsdl/test_multiplefault.rb: diff --git a/lib/open-uri.rb b/lib/open-uri.rb index 5aaa5c4f9c..168bc0a76d 100644 --- a/lib/open-uri.rb +++ b/lib/open-uri.rb @@ -443,16 +443,35 @@ module URI # ftp_proxy, no_proxy, etc. # If there is no proper proxy, nil is returned. # - # The enveironment variable CGI_http_proxy and CGI_HTTP_PROXY is used - # instead of http_proxy and HTTP_PROXY in the CGI environment because - # HTTP_PROXY can be set by Proxy: header sent by a CGI client. + # Note that capitalized variables (HTTP_PROXY, FTP_PROXY, NO_PROXY, etc.) + # are examined too. + # + # But http_proxy and HTTP_PROXY is treated specially under CGI environment. + # It's because HTTP_PROXY may be set by Proxy: header. + # So HTTP_PROXY is not used. + # http_proxy is not used too if the variable is case insentitive. + # CGI_HTTP_PROXY can be used instead. def find_proxy name = self.scheme.downcase + '_proxy' - if ENV.include? 'REQUEST_METHOD' # in CGI? - # Use CGI_HTTP_PROXY. cf. libwww-perl. - name = "CGI_#{name}" if /\Ahttp_/i =~ name + proxy_uri = nil + if name == 'http_proxy' && ENV.include?('REQUEST_METHOD') # CGI? + # HTTP_PROXY conflicts with *_proxy for proxy settings and + # HTTP_* for header informatin in CGI. + # So it should be careful to use it. + case_sentsitive = /djgpp|bccwin32|mingw|mswin32|mswince|emx/ !~ RUBY_PLATFORM + if case_sentsitive + # http_proxy is safe to use. + proxy_uri = ENV[name] + end + if !proxy_uri + # Use CGI_HTTP_PROXY. cf. libwww-perl. + proxy_uri = ENV["CGI_#{name.upcase}"] + end + else + proxy_uri = ENV[name] || ENV[name.upcase] end - if proxy_uri = ENV[name] || ENV[name.upcase] + + if proxy_uri proxy_uri = URI.parse(proxy_uri) name = 'no_proxy' if no_proxy = ENV[name] || ENV[name.upcase]