[#10193] String.ord — David Flanagan <david@...>

Hi,

41 messages 2007/02/05
[#10197] Re: String.ord — Yukihiro Matsumoto <matz@...> 2007/02/06

Hi,

[#10198] Re: String.ord — David Flanagan <david@...> 2007/02/06

Yukihiro Matsumoto wrote:

[#10199] Re: String.ord — Daniel Berger <djberg96@...> 2007/02/06

David Flanagan wrote:

[#10200] Re: String.ord — David Flanagan <david@...> 2007/02/06

Daniel Berger wrote:

[#10208] Re: String.ord — "Nikolai Weibull" <now@...> 2007/02/06

On 2/6/07, David Flanagan <david@davidflanagan.com> wrote:

[#10213] Re: String.ord — David Flanagan <david@...> 2007/02/06

Nikolai Weibull wrote:

[#10215] Re: String.ord — "Nikolai Weibull" <now@...> 2007/02/06

On 2/6/07, David Flanagan <david@davidflanagan.com> wrote:

[#10216] Re: String.ord — David Flanagan <david@...> 2007/02/07

Nikolai Weibull wrote:

[#10288] Socket library should support abstract unix sockets — <noreply@...>

Bugs item #8597, was opened at 2007-02-13 16:10

12 messages 2007/02/13

[#10321] File.basename fails on Windows root paths — <noreply@...>

Bugs item #8676, was opened at 2007-02-15 10:09

11 messages 2007/02/15

[#10323] Trouble with xmlrpc — James Edward Gray II <james@...>

Some of the Ruby code used by TextMate makes use of xmlrpc/

31 messages 2007/02/15
[#10324] Re: Trouble with xmlrpc — "Berger, Daniel" <Daniel.Berger@...> 2007/02/15

> -----Original Message-----

[#10326] Re: Trouble with xmlrpc — James Edward Gray II <james@...> 2007/02/15

On Feb 15, 2007, at 1:29 PM, Berger, Daniel wrote:

[#10342] Re: Trouble with xmlrpc — James Edward Gray II <james@...> 2007/02/16

While I am complaining about xmlrpc, we have another issue. It's

[#10343] Re: Trouble with xmlrpc — Alex Young <alex@...> 2007/02/16

James Edward Gray II wrote:

[#10344] Re: Trouble with xmlrpc — James Edward Gray II <james@...> 2007/02/16

On Feb 16, 2007, at 12:08 PM, Alex Young wrote:

open-uri proxy authentication for 1.8.6

From: Eric Hodel <drbrain@...7.net>
Date: 2007-02-16 01:52:51 UTC
List: ruby-core #10329
I'd like to see open-uri backported from trunk to ruby_1_8.  I wasn't  
able to get a tested patch before now, but this will backport just  
open-uri's proxy authentication from trunk.

If possible, merging the whole open-uri.rb would be preferred.  As  
Anatol's mail says, it was included wholesale in RubyGems 0.9.2 and  
works fine.

Begin forwarded message:

> From: "Anatol Pomozov" <anatol.pomozov@gmail.com>
> Date: February 15, 2007 13:19:08 PST
> To: rubygems-developers@rubyforge.org
> Subject: Re: [Rubygems-developers] lib/rubygems/open-uri.rb needs  
> to stay gone
> List-Id: <rubygems-developers.rubyforge.org>
>
> OK. Here is patch that contains proxy authorization changes.
>
> But as for me I would just copy open-uri.rb from trunk to 1.8.5  
> branch, because of 2 reasons
> 1) version from trunk is tested much better (we've used it in  
> rubygems-0.9.2)
> 2) It does not contained any API changes. Trunk version fixes 2  
> bugs: with proxy authorization and with SSL.
>
> Anyway if copying is not possible (but I am still voting for it) I  
> would like that anyone from you try to test this patch. Just apply  
> patch to your current open-uri.rb file and remove open-uri lib from  
> rubygems.
>
> I've just tested it. WinXP ruby 1.8.4, rubygems 0.9.2. Works fine.
>
>

Attachments (1)

proxy_changes.diff (4.25 KB, text/x-diff)
Index: lib/open-uri.rb
===================================================================
--- lib/open-uri.rb (revision 11758)
+++ lib/open-uri.rb (working copy)
@@ -91,6 +91,7 @@
 module OpenURI
   Options = {
     :proxy => true,
+    :proxy_http_basic_authentication => true,
     :progress_proc => true,
     :content_length_proc => true,
     :http_basic_authentication => true,
@@ -142,16 +143,40 @@
   end
 
   def OpenURI.open_loop(uri, options) # :nodoc:
-    case opt_proxy = options.fetch(:proxy, true)
+    proxy_opts = []
+    proxy_opts << :proxy_http_basic_authentication if options.include? :proxy_http_basic_authentication
+    proxy_opts << :proxy if options.include? :proxy
+    proxy_opts.compact!
+    if 1 < proxy_opts.length
+      raise ArgumentError, "multiple proxy options specified"
+    end
+    case proxy_opts.first
+    when :proxy_http_basic_authentication
+      opt_proxy, proxy_user, proxy_pass = options.fetch(:proxy_http_basic_authentication)
+      proxy_user = proxy_user.to_str
+      proxy_pass = proxy_pass.to_str
+      if opt_proxy == true
+        raise ArgumentError.new("Invalid authenticated proxy option: #{options[:proxy_http_basic_authentication].inspect}")
+      end
+    when :proxy
+      opt_proxy = options.fetch(:proxy)
+      proxy_user = nil
+      proxy_pass = nil
+    when nil
+      opt_proxy = true
+      proxy_user = nil
+      proxy_pass = nil
+    end
+    case opt_proxy
     when true
-      find_proxy = lambda {|u| u.find_proxy}
+      find_proxy = lambda {|u| pxy = u.find_proxy; pxy ? [pxy, nil, nil] : nil}
     when nil, false
       find_proxy = lambda {|u| nil}
     when String
       opt_proxy = URI.parse(opt_proxy)
-      find_proxy = lambda {|u| opt_proxy}
+      find_proxy = lambda {|u| [opt_proxy, proxy_user, proxy_pass]}
     when URI::Generic
-      find_proxy = lambda {|u| opt_proxy}
+      find_proxy = lambda {|u| [opt_proxy, proxy_user, proxy_pass]}
     else
       raise ArgumentError.new("Invalid proxy option: #{opt_proxy}")
     end
@@ -200,7 +225,8 @@
 
   def OpenURI.open_http(buf, target, proxy, options) # :nodoc:
     if proxy
-      raise "Non-HTTP proxy URI: #{proxy}" if proxy.class != URI::HTTP
+      proxy_uri, proxy_user, proxy_pass = proxy
+      raise "Non-HTTP proxy URI: #{proxy_uri}" if proxy_uri.class != URI::HTTP
     end
 
     if target.userinfo && "1.9.0" <= RUBY_VERSION
@@ -213,16 +239,23 @@
     if URI::HTTP === target
       # HTTP or HTTPS
       if proxy
-        klass = Net::HTTP::Proxy(proxy.host, proxy.port)
+        if proxy_user && proxy_pass
+          klass = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port, proxy_user, proxy_pass)
+        else
+          klass = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port)
+        end
       end
       target_host = target.host
       target_port = target.port
       request_uri = target.request_uri
     else
       # FTP over HTTP proxy
-      target_host = proxy.host
-      target_port = proxy.port
+      target_host = proxy_uri.host
+      target_port = proxy_uri.port
       request_uri = target.to_s
+      if proxy_user && proxy_pass
+        header["Proxy-Authorization"] = 'Basic ' + ["#{proxy_user}:#{proxy_pass}"].pack('m').delete("\r\n")
+      end
     end
 
     http = klass.new(target_host, target_port)
@@ -470,6 +503,21 @@
     #  When false or nil is given, the environment variables are ignored and
     #  connection will be made to a server directly.
     #
+    # [:proxy_http_basic_authentication]
+    #  Synopsis:
+    #    :proxy_http_basic_authentication => ["http://proxy.foo.com:8000/", "proxy-user", "proxy-password"]
+    #    :proxy_http_basic_authentication => [URI.parse("http://proxy.foo.com:8000/"), "proxy-user", "proxy-password"]
+    #   
+    #  If :proxy option is specified, the value should be an Array with 3 elements.
+    #  It should contain a proxy URI, a proxy user name and a proxy password.
+    #  The proxy URI should be a String, an URI or nil.
+    #  The proxy user name and password should be a String.
+    #
+    #  If nil is given for the proxy URI, this option is just ignored.
+    #
+    #  If :proxy and :proxy_http_basic_authentication is specified, 
+    #  ArgumentError is raised.
+    #
     # [:http_basic_authentication]
     #  Synopsis:
     #    :http_basic_authentication=>[user, password]

In This Thread

Prev Next