1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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/trunk@7944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2005-02-11 02:47:11 +00:00
parent 6ef3fe6349
commit db6d5b15be
2 changed files with 22 additions and 2 deletions

View file

@ -1,3 +1,9 @@
Fri Feb 11 11:33:53 2005 Tanaka Akira <akr@m17n.org>
* lib/open-uri.rb (URI::HTTP#proxy_open): new option supported:
:http_basic_authentication.
suggested by Kent Sibilev. [ruby-core:4392]
Thu Feb 10 13:52:42 2005 NAKAMURA Usaku <usa@ruby-lang.org> Thu Feb 10 13:52:42 2005 NAKAMURA Usaku <usa@ruby-lang.org>
* configure.in, win32/Makefile.sub (LIBS, COMMON_HEADERS): use * configure.in, win32/Makefile.sub (LIBS, COMMON_HEADERS): use

View file

@ -95,9 +95,9 @@ module OpenURI
:proxy => true, :proxy => true,
:progress_proc => true, :progress_proc => true,
:content_length_proc => true, :content_length_proc => true,
:http_basic_authentication => true,
} }
def OpenURI.check_options(options) # :nodoc: def OpenURI.check_options(options) # :nodoc:
options.each {|k, v| options.each {|k, v|
next unless Symbol === k next unless Symbol === k
@ -381,6 +381,15 @@ module OpenURI
# When false or nil is given, the environment variables are ignored and # When false or nil is given, the environment variables are ignored and
# connection will be made to a server directly. # 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] # [:content_length_proc]
# Synopsis: # Synopsis:
# :content_length_proc => lambda {|content_length| ... } # :content_length_proc => lambda {|content_length| ... }
@ -547,8 +556,13 @@ module URI
require 'net/http' require 'net/http'
resp = nil 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| Net::HTTP.start(self.host, self.port) {|http|
http.request_get(uri.to_s, header) {|response| http.request(req) {|response|
resp = response resp = response
if options[:content_length_proc] && Net::HTTPSuccess === resp if options[:content_length_proc] && Net::HTTPSuccess === resp
if resp.key?('Content-Length') if resp.key?('Content-Length')