aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/lib/active_resource/connection.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activeresource/lib/active_resource/connection.rb')
-rw-r--r--activeresource/lib/active_resource/connection.rb32
1 files changed, 27 insertions, 5 deletions
diff --git a/activeresource/lib/active_resource/connection.rb b/activeresource/lib/active_resource/connection.rb
index fb3fde59d6..ef57c1f8b2 100644
--- a/activeresource/lib/active_resource/connection.rb
+++ b/activeresource/lib/active_resource/connection.rb
@@ -16,7 +16,7 @@ module ActiveResource
:delete => 'Accept'
}
- attr_reader :site, :user, :password, :timeout
+ attr_reader :site, :user, :password, :timeout, :proxy
attr_accessor :format
class << self
@@ -41,6 +41,11 @@ module ActiveResource
@password = URI.decode(@site.password) if @site.password
end
+ # Set the proxy for remote service.
+ def proxy=(proxy)
+ @proxy = proxy.is_a?(URI) ? proxy : URI.parse(proxy)
+ end
+
# Sets the user for remote service.
def user=(user)
@user = user
@@ -132,10 +137,27 @@ module ActiveResource
# Creates new Net::HTTP instance for communication with the
# remote service and resources.
def http
- http = Net::HTTP.new(@site.host, @site.port)
- http.use_ssl = @site.is_a?(URI::HTTPS)
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
- http.read_timeout = @timeout if @timeout # If timeout is not set, the default Net::HTTP timeout (60s) is used.
+ configure_http(new_http)
+ end
+
+ def new_http
+ if @proxy
+ Net::HTTP.new(@site.host, @site.port, @proxy.host, @proxy.port, @proxy.user, @proxy.password)
+ else
+ Net::HTTP.new(@site.host, @site.port)
+ end
+ end
+
+ def configure_http(http)
+ http.use_ssl = @site.is_a?(URI::HTTPS)
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
+
+ # Net::HTTP timeouts default to 60 seconds.
+ if @timeout
+ http.open_timeout = @timeout
+ http.read_timeout = @timeout
+ end
+
http
end