Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow you to set RequestOptions#proxy

  • Loading branch information...
commit 03504db53b65d82f4087b99347ae9fb428b65238 1 parent aa8b420
@technoweenie authored
Showing with 28 additions and 1 deletion.
  1. +12 −1 lib/faraday/options.rb
  2. +16 −0 test/options_test.rb
View
13 lib/faraday/options.rb
@@ -90,6 +90,14 @@ def inspect
class RequestOptions < Options.new(:params_encoder, :proxy, :bind,
:timeout, :open_timeout, :boundary,
:oauth)
+
+ def []=(key, value)
+ if key && key.to_sym == :proxy
+ super(key, value ? ProxyOptions.from(value) : nil)
+ else
+ super(key, value)
+ end
+ end
end
class SSLOptions < Options.new(:verify, :ca_file, :ca_path, :verify_mode,
@@ -112,7 +120,10 @@ def self.from(value)
case value
when String then value = {:uri => Connection.URI(value)}
when URI then value = {:uri => value}
- when Hash, Options then value[:uri] = Connection.URI(value[:uri])
+ when Hash, Options
+ if uri = value.delete(:uri)
+ value[:uri] = Connection.URI(uri)
+ end
end
super(value)
end
View
16 test/options_test.rb
@@ -6,6 +6,22 @@ class Options < Faraday::Options.new(:a, :b, :c)
options :c => SubOptions
end
+ def test_request_proxy_setter
+ options = Faraday::RequestOptions.new
+ assert_nil options.proxy
+
+ assert_raises NoMethodError do
+ options[:proxy] = {:booya => 1}
+ end
+
+ options[:proxy] = {:user => 'user'}
+ assert_kind_of Faraday::ProxyOptions, options.proxy
+ assert_equal 'user', options.proxy.user
+
+ options.proxy = nil
+ assert_nil options.proxy
+ end
+
def test_from_options
options = Options.new 1
Please sign in to comment.
Something went wrong with that request. Please try again.