diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-02-11 02:47:11 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-02-11 02:47:11 +0000 |
commit | 417073640454c7bd7d6fc184342ea47e29dab717 (patch) | |
tree | a9005c4b39292adedca112e33b6359d8d1f1148a /lib/open-uri.rb | |
parent | 77f047ec898328b26a77cda5f1e5862604ef0d4c (diff) |
* lib/open-uri.rb (URI::HTTP#proxy_open): new option supported:
:http_basic_authentication.
suggested by Kent Sibilev. [ruby-core:4392]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/open-uri.rb')
-rw-r--r-- | lib/open-uri.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/open-uri.rb b/lib/open-uri.rb index 2c87e29224..ff25b849af 100644 --- a/lib/open-uri.rb +++ b/lib/open-uri.rb @@ -95,9 +95,9 @@ module OpenURI :proxy => true, :progress_proc => true, :content_length_proc => true, + :http_basic_authentication => true, } - def OpenURI.check_options(options) # :nodoc: options.each {|k, v| next unless Symbol === k @@ -381,6 +381,15 @@ module OpenURI # When false or nil is given, the environment variables are ignored and # connection will be made to a server directly. # + # [:http_basic_authentication] + # Synopsis: + # :http_basic_authentication=>[user, password] + # + # If :http_basic_authentication is specified, + # the value should be an array which contains 2 strings: + # username and password. + # It is used for HTTP Basic authentication defined by RFC 2617. + # # [:content_length_proc] # Synopsis: # :content_length_proc => lambda {|content_length| ... } @@ -547,8 +556,13 @@ module URI require 'net/http' resp = nil + req = Net::HTTP::Get.new(uri.to_s, header) + if options.include? :http_basic_authentication + user, pass = options[:http_basic_authentication] + req.basic_auth user, pass + end Net::HTTP.start(self.host, self.port) {|http| - http.request_get(uri.to_s, header) {|response| + http.request(req) {|response| resp = response if options[:content_length_proc] && Net::HTTPSuccess === resp if resp.key?('Content-Length') |