lib/http/client.rb in http-0.8.0 vs lib/http/client.rb in http-0.8.1
- old
+ new
@@ -1,5 +1,7 @@
+require "forwardable"
+
require "cgi"
require "uri"
require "http/form_data"
require "http/options"
@@ -8,10 +10,11 @@
require "http/uri"
module HTTP
# Clients make requests and receive responses
class Client
+ extend Forwardable
include Chainable
CONNECTION = "Connection".freeze
KEEP_ALIVE = "Keep-Alive".freeze
CLOSE = "close".freeze
@@ -56,10 +59,15 @@
options.cache.perform(req, options) do |r, opts|
make_request(r, opts)
end
end
+ # @!method persistent?
+ # @see Options#persistent?
+ # @return [Boolean] whenever client is persistent
+ def_delegator :default_options, :persistent?
+
def make_request(req, options)
verify_connection!(req.uri)
@state = :dirty
@@ -77,15 +85,13 @@
@connection.finish_response if req.verb == :head
@state = :clean
res
-
- # On any exception we reset the conn. This is a safety measure, to ensure
- # we don't have conns in a bad state resulting in mixed requests/responses
rescue
- close if default_options.persistent?
-
+ # On any exception we reset the conn. This is a safety measure, to ensure
+ # we don't have conns in a bad state resulting in mixed requests/responses
+ close if persistent?
raise
end
def close
@connection.close if @connection