lib/faraday/connection.rb in faraday-1.0.0.pre.rc1 vs lib/faraday/connection.rb in faraday-1.0.0

- old
+ new

@@ -12,11 +12,11 @@ # conn.get 'nigiri' # # => #<Faraday::Response> # class Connection # A Set of allowed HTTP verbs. - METHODS = Set.new %i[get post put delete head patch options trace connect] + METHODS = Set.new %i[get post put delete head patch options trace] # @return [Hash] URI query unencoded key/value pairs. attr_reader :params # @return [Hash] unencoded HTTP header key/value pairs. @@ -97,11 +97,10 @@ if options.proxy ProxyOptions.from(options.proxy) else proxy_from_env(url) end - @temp_proxy = @proxy end # Sets the Hash of URI query unencoded key/value pairs. # @param hash [Hash] def params=(hash) @@ -116,10 +115,17 @@ extend Forwardable def_delegators :builder, :build, :use, :request, :response, :adapter, :app + # Closes the underlying resources and/or connections. In the case of + # persistent connections, this closes all currently open connections + # but does not prevent new connections from being made. + def close + app.close + end + # @!method get(url = nil, params = nil, headers = nil) # Makes a GET HTTP request without a body. # @!scope class # # @param url [String] The optional String base URL to use as a prefix for @@ -168,25 +174,10 @@ # conn.delete '/items/1' # # @yield [Faraday::Request] for further request customizations # @return [Faraday::Response] - # @!method connect(url = nil, params = nil, headers = nil) - # Makes a CONNECT HTTP request without a body. - # @!scope class - # - # @param url [String] The optional String base URL to use as a prefix for - # all requests. Can also be the options Hash. - # @param params [Hash] Hash of URI query unencoded key/value pairs. - # @param headers [Hash] unencoded HTTP header key/value pairs. - # - # @example - # conn.connect '/items/1' - # - # @yield [Faraday::Request] for further request customizations - # @return [Faraday::Response] - # @!method trace(url = nil, params = nil, headers = nil) # Makes a TRACE HTTP request without a body. # @!scope class # # @param url [String] The optional String base URL to use as a prefix for @@ -488,15 +479,12 @@ def run_request(method, url, body, headers) unless METHODS.include?(method) raise ArgumentError, "unknown http method: #{method}" end - # Resets temp_proxy - @temp_proxy = proxy_for_request(url) - request = build_request(method) do |req| - req.options = req.options.merge(proxy: @temp_proxy) + req.options.proxy = proxy_for_request(url) req.url(url) if url req.headers.update(headers) if headers req.body = body if body yield(req) if block_given? end @@ -512,10 +500,10 @@ # @return [Faraday::Request] def build_request(method) Request.create(method) do |req| req.params = params.dup req.headers = headers.dup - req.options = options + req.options = options.dup yield(req) if block_given? end end # Build an absolute URL based on url_prefix.