Object
The Configuration class encapsulates a set of HTTP defaults. The configuration can made either global or all requests, or it can be applied only within a block. Configuration blocks can also set an additional set of options which take precedence over the initialization options.
Available options are :proxy_host, :proxy_port, :proxy_user, :proxy_password, :no_proxy, :read_timeout, :open_timeout, and :proxy. This last value can either contain a proxy string or the symbol :none for no proxy or :environment to use the values in the HTTP_PROXY/http_proxy and NO_PROXY/no_proxy environment variables.
If you specify a proxy, but don't want it to be used for certain hosts, specify the domain names in the :no_proxy option. This can either be an array or a comma delimited string. A request to a host name which ends with any of these values will not be proxied.
The normal functionality for Net::HTTP is still available, so you can set proxies and timeouts manually if needed. Because of the way in which https calls are made, you cannot configure a special proxy just for https calls.
Get the current configuration that is in scope.
# File lib/http_configuration.rb, line 111 def current stack = Thread.current[:net_http_configuration] config = stack.last if stack config || global end
# File lib/http_configuration.rb, line 59 def initialize (options = {}) @default_options = options.dup expand_proxy_config!(@default_options) end
# File lib/http_configuration.rb, line 84 def no_proxy? (host, options) return false unless options[:no_proxy].kind_of?(Array) host = host.downcase options[:no_proxy].each do |pattern| pattern = pattern.downcase return true if host[-pattern.length, pattern.length] == pattern end return false end
Set the options for a global configuration used for all HTTP requests. The global configuration can be cleared by setting nil
# File lib/http_configuration.rb, line 98 def set_global (options) if options @global = Configuration.new(options) else @global = nil end end
Get the specified option for the configuration.
# File lib/http_configuration.rb, line 65 def [] (name) @default_options[name] end
Apply the configuration to the block. If any options are provided, they will override the default options for the configuration.
# File lib/http_configuration.rb, line 71 def apply (options = {}) options = @default_options.merge(options) expand_proxy_config!(options) Thread.current[:net_http_configuration] ||= [] Thread.current[:net_http_configuration].push(options) begin return yield ensure Thread.current[:net_http_configuration].pop end end
Generated with the Darkfish Rdoc Generator 2.